What does 'Only a ReactOwner can have refs.' mean?

前端 未结 12 2542
时光说笑
时光说笑 2020-11-27 15:50

I have a simple react component with a form in it:

var AddAppts = React.createClass({
    handleClick:          


        
12条回答
  •  迷失自我
    2020-11-27 16:15

    This is FYI for people using react and redux-devtools who are getting OP's message. Your structure looks like

    project
      client
      node_modules
        react
        redux-devtools
          node_modules
            react
    

    The code in client will require the first react module; that in redux-devtools will require the other react. The react module keeps state and assumes it has all the state.

    You get the OP's message because your state is split between the 2 react modules. This situation is what I believe @asbjornenge refers to.

    I was bundling the client code with webpack, so I used that to handle the issue. You can force all require and import to always use the first react by adding the following to webpack.config.js

    module.exports = {
      ...
      resolve: {
        alias: {
          'react': path.join(__dirname, 'node_modules', 'react')
        },
        extensions: ['', '.js']
      },
      ...
    );
    

    I have not looked into what I would need to do if the situation occurred with unbundled code running on node.

提交回复
热议问题