Questions...
Q2 Arun is implementing theme support for his application and is using context api. However he is facing an issue, setTheme is not a function for the code written below. Among the given modification options, select the correct option(s) which can fix the issue in below code. context.js const AppContext = React.createContext({ theme: 'light', setTheme: () => { } }); Appl.js function App1() { const [theme, setTheme] = useState("); const setNewTheme = (new Theme) => { // logic to change the theme setTheme(new Theme); } return <AppContext.Provider value={{ theme, setNewTheme }}> <div>From Appl component</div> <App2 > </AppContext.Provider> ) 3/1 } App2.js function App20) { const { setTheme } = useContext(AppContext); useEffect(( => { setTheme('dark'); }, 01) return ( <div>From App2 component</div> a) context.js: const AppContext = React.createContext({}); b) Appl.js: <AppContext.Provider value={{ theme: theme, setTheme: setNewTheme }}> </AppContext.Provider> c) Using AppContext.Consumer in App2 instead of useContext d) None of the above
React Js Q2 Arun is implementing theme support for his application and is using context api. However he is facing an issue, setTh
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am