Ребенок ожидает noOfDice в качестве реквизита, поэтому он работает в одном сценарии, а не в другом. Вы должны оставить имя таким же. Я отредактировал твой код с именем реквизита как acceptedNumber
. Также проверьте, правильно ли импортирован дочерний компонент.
Попробуйте:
// NoOfSides
class NoOfSides extends React.Component {
constructor(props) {
super(props);
this.state = { mystate: 6 };
}
render() {
return (<div>
<h1>Number of Sides</h1>
<h2 >
{this.state.mystate}
</h2>
<Child acceptedNumber={this.state.mystate} />
</div>
);
}
};
// NoOfDice
class NoOfDice extends React.Component {
constructor(props) {
super(props);
this.state = { mystate: 1 };
}
render() {
return (<div>
<h1>Number of Dice</h1>
<h2 >
{this.state.mystate}
</h2>
<Child acceptedNumber={this.state.mystate} />
</div>
);
}
};
// Child
class Child extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h1>{this.props.acceptedNumber}</h1>
</div>
)
}
}