React update parent when children component updated

Why parent component always show less 1, than child?
It’s not re-render after first update.

Why parent component always show less 1, than child?
It’s not re-render after first update.

export const Parent = (props) => {
  const [count, setCount] = React.useState(0);
  return (
    <View>
      <Text>Parent: {count}</Text>
      <Child updateCount={setCount} />
    </View>
  );
};

const Child = (props) => {
  const [count, setCount] = React.useState(0);

  const updateCount = () => {
    setCount((count) => count + 1);
    return props.updateCount(count);
  };
  return (
    <View>
      <Text>Child: {count}</Text>
      <Button title="add" onPress={updateCount} />
    </View>
  );
};

75 thoughts on “React update parent when children component updated”

  1. i need a loan desperately, i need loan embassy finder. i need 2 lakhs loan need loan need a loan fast i need an emergency loan now, cash advance loans online, cash advance loans, cash advance loans, cash advance loans with no credit check. Economics lending to commerce, financial institution .

    Reply

Leave a Comment