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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 143 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply