简体   繁体   English

提供者react-redux中的错误

[英]Error in Provider react-redux

When i'm run my simple program 当我运行我的简单程序

Index.js Index.js

function test(state = []) {
    return state
}

const store = createStore(test);

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

App.js App.js

const App = () => {
   return ( <h1 > Yo < /h1>)
}

export default App;

i get something like this: 我得到这样的东西:

Error: React.Children.only expected to receive a single React element child.
    at invariant (invariant.js:44)
    at Object.onlyChild [as only] (onlyChild.js:33)
    at Provider.render (Provider.js:49)
    at ReactCompositeComponent.js:795
    at measureLifeCyclePerf (ReactCompositeComponent.js:75)

What i'm do wrong? 我做错了什么? When i delete Provider program render App 当我删除提供者程序渲染应用程序时

This error typically occurs when you have more than one children retrieved (for example, if you render a component that has several elements but isn't wrapped in a div). 当您检索到多个子级时,通常会发生此错误(例如,如果渲染的组件具有多个元素,但没有包装在div中)。 Now I can't say much from looking at only the code above, try to wrap the content inside <Provider ... /> in a <div> 现在,仅看上面的代码我不能说太多,尝试将内容包装在<div>中的<div> <Provider ... />

Your store should be an object, not an array. 您的商店应该是一个对象,而不是数组。 Change your test reducer to 将您的测试减速器更改为

function test(state = {}) {
    return state
}

You can store array values in your store but it needs to be an object at the top level. 您可以将数组值存储商店中,但它必须是顶层的对象。

{
  stuff: ['a', 'b'],
}

暂无
暂无

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

相关问题 错误:找不到 react-redux 上下文值; 请确保组件被包裹在一个<provider> : Redux 与 NextJS</provider> - Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>: Redux with NextJS 在react-redux中连接错误? - Error with connect in react-redux? 错误:找不到 react-redux 上下文值; 请确保组件被包裹在一个<Provider>在使用 useselector 时 - Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> while using useselector React-Redux错误提供给提供者的对象类型为对象的无效子属性prop - React-Redux error Invalid prop `children` of type `object` supplied to `Provider` react-redux Provider在IE 10/11中给出错误“onlyChild必须通过一个孩子只有一个孩子” - react-redux Provider gives error “onlyChild must be passed a children with exactly one child” in IE 10/11 错误:找不到 react-redux 上下文值; 请确保组件被包裹在一个<provider></provider> - Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider> React Native - react-redux PropTypes 错误 - React Native - react-redux PropTypes error react-redux:了解提供者和代表性组件之间的通信 - react-redux: understanding communication between Provider and representational components react-redux 提供者的上下文实例属性是什么? - What is the context instance prop of react-redux provider? React-Redux 连接未从 Provider 获取存储 - React-Redux connect isn't getting store from Provider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM