React上下文API包裹在index.js文件归档时
我正在学习上下文API并在上下文中创建一个添加篮
import React, { createContext } from "react";
const Cart = createContext();
function Context({ childern }) {
return <Cart.Provider>{childern}</Cart.Provider>;
}
export default Context;
。
import Context from "./context/Context";
<Context>
<App />
</Context>
功能 在浏览器上执行此操作后,它没有显示任何错误,没有我创建的单个组件,但是当我解开组件时,它可以正常工作
I am learning about context API and creating an add basket functionality in the Context.js file I have created a context that which will I use for my application it's code is
import React, { createContext } from "react";
const Cart = createContext();
function Context({ childern }) {
return <Cart.Provider>{childern}</Cart.Provider>;
}
export default Context;
now I am wrapping my App component around it in the index.js file
import Context from "./context/Context";
<Context>
<App />
</Context>
but after doing this on the browser it display nothing no error not a single component that I have created is displayed but when I unwrapped the component it works fine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在它将起作用。只需在提供商中的道具和“ Props.Children”中添加“道具”。
Now it will work. Just add "props" in props and "props.children" in provider.