简体   繁体   English

如何将提供者正确地附加到reactDOM.render

[英]How to attach provider properly to the reactDOM.render

I wanted to try redux with a framework 7 react template. 我想尝试使用框架7 react模板进行redux。 I installed redux, react-redux on top of the teamplate and copy paste all code from reduxjs todoList example into my template, but I have problem with provider integration. 我在团队面板上安装了redux,react-redux并将复制的所有代码从reduxjs todoList示例粘贴到模板中,但是提供程序集成存在问题。

I get Target container is not a DOM element error for below code 我得到目标容器不是以下代码的DOM元素错误

// Mount React App
ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  React.createElement(App),
  document.getElementById('app'),
);

Initialy it was like this and it was working, I only added provider 最初是这样的并且正在工作,我只添加了提供程序

// Mount React App
ReactDOM.render(
  React.createElement(App),
  document.getElementById('app'),
);

<App /> gets compiled to React.createElement(App) , so you only need the first Provider part of your code since App is a child to Provider . <App /> 被编译为React.createElement(App) ,因此您仅需要代码的第一个Provider部分,因为AppProvider的子级。

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('app')
);

It should be 它应该是

 // Mount React App ReactDOM.render( <Provider store={store}> <App /> </Provider>, document.getElementById('app'), ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM