3月12日日记:【WEBPACK】【REACT】

2019-03-13  本文已影响0人  钟志弘

关于webpack 遇到的问题

本次webpack配置一切顺利,需要注意的地方有两点:

{
  test: /\.js$/,
  exclude: /(node_modules)/,
  ...
}
"Utilities":"./Utilities/"

正确的是:

Utilities: path.resolve(__dirname, "Utilities/")

关于React

今天遇到的问题是:

...
<Color color={color} />
-----------------------------
const Color = ({ color }) => ... // wrong!

而应该是:

<Color {...color} />
const Color = ({ title , color, rating }) =>... // correct
const AddColorPanel = ( { onAddColor }) =>{
  
  const submit = e => {
    e.preventDefault();
    onAddColor({ title: _title.value, color: _color.value});

    _title.value ="";
    _color.value ="";
  }

  return (
    <form onSubmit = {submit}>
      <input type="text" ref={(input) => _title = input} placeholder="color title..." />
      <input type="color" ref={(input) => _color = input} />
      <button type="submit">submit</button>
    </form>
  )
}

上面的是错误的,正确应该是:

const AddColorPanel = ( { onAddColor }) =>{
  let _title, _color;
  
  const submit = e => {
    e.preventDefault();
    // let {_title, _color} = this.refs  
    onAddColor({ title: _title.value, color: _color.value});

    _title.value ="";
    _color.value ="";
  }

  return (
    <form onSubmit = {submit}>
      <input type="text" ref={(input) => _title = input} placeholder="color title..." />
      <input type="color" ref={(input) => _color = input} />
      <button type="submit">submit</button>
    </form>
  )
}

或者以字符形式使用它。

上一篇 下一篇

猜你喜欢

热点阅读