У меня есть кнопка Refre sh, которая должна изменить состояние в Компоненте, и она должна повторно обработать его дочерний компонент Excercise. Состояние меняется, я вижу в console.log, но почему нет перерисовки компонента chd? (если вы введете что-то во ввод и нажмете Refe sh, ничего не произойдет)
class ListComponent extends React.Component{
constructor(props){
super(props);
this.state = {reload: true};
};
refreshComponent(){
if (this.state.reload){
this.setState({reload: false })
console.log(this.state.reload);
} else if (!this.state.reload) {
this.setState({reload: true })
console.log(this.state.reload);
}
};
render () {
return (
<div>
{WordList.map(word => {
return <li><Excercise wordObject={word}></Excercise></li>}) }
<button onClick={()=>this.refreshComponent()}>Refresh</button>
</div>
)
}
}
export default ListComponent;
//chd component:
class Excercise extends React.Component {
render(){
return (<div>
<table>
<tbody>
<td>
{this.props.wordObject.danishWord}
<input
type={'text'}
></input>
</td>
</tbody>
</table>
</div>
)
}