I have declared a React context in indexa.js and I'm trying to access the context value set in App.js in Employee.js. But it's not rendering the value I'm new to React. Please help me out. Thanks in advance
//index.js
export const employeeContext = React.createContext();
const AppContextInteration = <App></App>
ReactDOM.render(AppContextInteration, document.getElementById('root'));
//App.js
export class App extends React.Component {
constructor(props) {
super(props);
this.state = {
EmpId: 1,
EmpName: 'xxx'
}
}
render() {
return (
<div>
<h1> App Component</h1>
<p> Employee Id : {this.state.EmpId}</p>
<employeeContext.Provider value={this.state} >
<Employee/>
</employeeContext.Provider>
</div>
)
}
}
//Employee.js
export class Employee extends React.Component {
context = employeeContext;
constructor(props) {
super(props);
console.log();
}
render() {
return (
<div>
<h1>Employee Component </h1>
<p> Employee Id : {this.context.EmpId} </p>
</div>
)
}
}