Page 1 of 1

Q2 Arun is implementing theme support for his application and is using context api. However he is facing an issue, setTh

Posted: Fri May 20, 2022 9:52 am
by answerhappygod
Q2 Arun Is Implementing Theme Support For His Application And Is Using Context Api However He Is Facing An Issue Setth 1
Q2 Arun Is Implementing Theme Support For His Application And Is Using Context Api However He Is Facing An Issue Setth 1 (109.21 KiB) Viewed 145 times
React Js 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