You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is useContext currently in the testing phase? After changing the isShow parameter of the context to true and rendering the TestConsumer component, the context obtained within the component is the default value, not the updated value after isShow has changed. Removing the isShow condition from {isShow && } under TestingContext.Provider, TestConsumer and its TestShow component also include a value.show. But at this time, TestShow is able to correctly obtain the value of value, not the default value.
`
export const useTest = () => {
const [value, setValue] = useState(Math.random().toString());
const [isShow, setIsShow] = useState(false);
return {
value,
isShow,
setIsShow,
};
};
const testContextValue = useTest();
const { value, isShow, setIsShow } = testContextValue;
useEffect(() => {
setTimeout(() => {
setIsShow(true);
}, 2000);
}, []);
<TestingContext.Provider value={testContextValue}>
{isShow && }
</TestingContext.Provider>
const TestConsumer = () => {
const value = useContext(TestingContext) as any;
Is useContext currently in the testing phase? After changing the isShow parameter of the context to true and rendering the TestConsumer component, the context obtained within the component is the default value, not the updated value after isShow has changed. Removing the isShow condition from {isShow && } under TestingContext.Provider, TestConsumer and its TestShow component also include a value.show. But at this time, TestShow is able to correctly obtain the value of value, not the default value.
`
export const useTest = () => {
const [value, setValue] = useState(Math.random().toString());
const [isShow, setIsShow] = useState(false);
return {
value,
isShow,
setIsShow,
};
};
const testContextValue = useTest();
const { value, isShow, setIsShow } = testContextValue;
useEffect(() => {
setTimeout(() => {
setIsShow(true);
}, 2000);
}, []);
<TestingContext.Provider value={testContextValue}>
{isShow && }
</TestingContext.Provider>
const TestConsumer = () => {
const value = useContext(TestingContext) as any;
return (
<>
{JSON.stringify(value)}
{value.isShow && }
111
</>
);
};
export default memo(TestConsumer);
const TestShow = () => {
const { value, isShow } = useContext(TestingContext) as any;
return
};
export default memo(TestShow);
`
The text was updated successfully, but these errors were encountered: