questions...
Q1 Arun created two components Appl and App2 as shown below. Both the components uses the same context named AppContext. AppContext is defined in context.js file. From Appl Arun sets the value of appUrl as 'http://ctx- example.com'. However, from App2 Arun is not able to get the value. Select a possible reason for this anomaly from the options listed below. Assume that all the required imports and exports statement are provided. context.js import React from 'react'; const url = export const AppContext = React.createContext(url); App1.js function App1() { return <AppContext.Provider value={'http://ctx-example.com'} > <div>From Appl component</div> </AppContext.Provider> ) } App2.js function App2() { const appUrl = useContext(AppContext); return <div>From App2 component</div> <div>{appUrl}</div> } a) Context Consumer is not used in App2 to get the value of the context b) Appl and App2 are neither nested components nor does it have a common parent component c) Context API's should be an object d) In App2, variable name should be 'url' and not ‘appUrl
React Js Q1 Arun created two components Appl and App2 as shown below. Both the components uses the same context named AppContext.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am