Q1 Arun created two components Appl and App2 as shown below. Both the components uses the same context named AppContext.

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

Q1 Arun created two components Appl and App2 as shown below. Both the components uses the same context named AppContext.

Post by answerhappygod »

Q1 Arun Created Two Components Appl And App2 As Shown Below Both The Components Uses The Same Context Named Appcontext 1
Q1 Arun Created Two Components Appl And App2 As Shown Below Both The Components Uses The Same Context Named Appcontext 1 (110.48 KiB) Viewed 72 times
React Js 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply