From ccda2ff9e8f0fb54586bef8bc878f7ca97569e3c Mon Sep 17 00:00:00 2001 From: minhphuongvong07 <142573902+minhphuongvong07@users.noreply.github.com> Date: Thu, 29 Feb 2024 08:34:00 +0900 Subject: [PATCH] fixed start props' error start props doesn't reflect the state of parent component --- src/components/counter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/counter.js b/src/components/counter.js index 3f46b7b..0c253e2 100644 --- a/src/components/counter.js +++ b/src/components/counter.js @@ -19,7 +19,11 @@ export default class Counter extends Component { beforeLoading: false, }; } - + componentDidUpdate(prevProps) { + if (prevProps.start !== this.props.start) { + this.setState({ count: this.props.start }); + } + } onPress(count, type) { const { onChangeBefore } = this.props;