indexa.js で React コンテキストを宣言し、App.js で設定されたコンテキスト値に Employee.js でアクセスしようとしています。しかし、それは私がReactに慣れていない価値をレンダリングしていません。私を助けてください。前もって感謝します
//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>
)
}
}