[英]blank screen after wrapping App component with react-context
I am writing the context API and everything is working fine but when I wrapped the App component with the context screen became blank我正在编写上下文 API 并且一切正常,但是当我用上下文屏幕包装 App 组件时变成空白
Code of contex上下文代码
import { useState } from "react";
import { createContext, useContext } from "react";
const chatContext = createContext();
const ChatContext = ({ childern }) => {
const [user, setuser] = useState();
return (
<chatContext.Provider value={{ user, setuser }}>
{childern}
</chatContext.Provider>
);
};
export const ChatState = () => {
return useContext(chatContext);
};
export default ChatContext;
code of index.js before wrapping contex包装contex之前的index.js代码
ReactDOM.render(
<React.StrictMode>
<Router>
<App />
</Router>
</React.StrictMode>,
document.getElementById("root")
);
** code after wrapping context api ** **包装上下文 api 后的代码**
import ChatContext from "./Context/ChatContext";
ReactDOM.render(
<ChatContext>
<Router>
<App />
</Router>
</ChatContext>,
document.getElementById("root")
);
but the screen becomes blank anyone how can help me.但是屏幕变成空白任何人都可以帮助我。
I tried to solve this problem but can not able to do so.我试图解决这个问题,但不能这样做。 plz anyone how can help me will be appricated
请任何人如何帮助我
i think you just misspelled children you wrote childern and if you fix how you wrote it the problem will be solved我想你只是拼错了孩子你写的孩子,如果你改正你写它的方式,问题就会解决
const ChatContext = ({ *childern* children }) => {
const [user, setuser] = useState();
return (
<chatContext.Provider value={{ user, setuser }}>
{*childern* children}
</chatContext.Provider>
);
};
export const ChatState = () => {
return useContext(chatContext);
};
export default ChatContext;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.