Conditional Operator for React Components, not updating

Viewed 36

I currently have 2 Components that work conditionally, but i would like it to update and change when the createdSavingsGoal state array is greater than 0 (i.e Not empty)

Then it shows a List.. When its empty it shows a Form that allows me to Post to that array. Currently i have to refresh that page but i would just like it to work. automatically

Im not brilliant with State so if im doing something obvious.

this.state = {
  createdSavingsGoal: "",
};

..

render() {
const { createdSavingsGoal } = this.state;
if (createdSavingsGoal.length > 0) {
  return <ViewSavingsGoal />;
} else {
  return <CreateSavingsGoal />;
}
0 Answers
Related