Answer the question
In order to leave comments, you need to log in
How not to override Context value (React)?
Hello.
context.js
export const ctx = {
a: 1
}
import React, {Provider} from 'react';
import {ctx} from './context';
const CTX = React.createContext(ctx);
function App() {
return (
<CTX.Provider value={ctx}>
<MyComponent />
</CTX.Provider>
);
}
<CTX.Provider value={ctx}>
<MyComponent />
</CTX.Provider>
Answer the question
In order to leave comments, you need to log in
Option 1:
const CTX = React.createContext();
const App = () => (
<CTX.Provider value={ctx}>
<MyComponent />
</CTX.Provider>
);
const CTX = React.createContext(ctx);
const App = () => (
<MyComponent />
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question