这是我试图创造的背景
import React,{Component, useState } from "react";
export const DojoContext = React.createContext()
const ThemeContextProvider = (props)=> {
const [theme, setTheme] = useState({
isLightTheme: true,
light: { syntax: "#555", ui: "#ddd", bg: "#eee" },
dark: { syntax: "#ddd", ui: "#333", bg: "#555" },
});
return (
<div>
<DojoContext.Provider value={{ ...theme }}>
{props.children}
</DojoContext.Provider>
</div>
);
}
export default ThemeContextProvider;
这里是App组件,它将所有其他组件 Package 为子组件
x一个一个一个一个x一个一个二个x
因此,我希望在单击按钮时在控制台打印上下文的值,以确保我可以访问它的值
1条答案
按热度按时间nimxete21#
您将上下文导出为一个命名变量,而在
Dojo
组件中导入它时,实际上导入的是ThemeContextProvider
试试看