Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - I'm having an issue with resetting the values back to 0 on submit #86

Open
verbowersock opened this issue Mar 30, 2022 · 1 comment

Comments

@verbowersock
Copy link

When I attempt to reset the values back to 0 after submitting, the component doesn't rerender

const [ozValue, setOzValue] = useState(0);
const [minuteValue, setMinuteValue] = useState(0);
const clearValues = () => {
    setOzValue(0);
    setMinuteValue(0);
  };

 const onSubmitNext = () => {
    setOzValue(0);
    setMinuteValue(0);
  };

  return (
    <KeyboardAwareScrollView contentContainerStyle={styles.modalContainer}>
      <Text style={styles.modalHeader}>{title}</Text>
      <View style={styles.numInputContainer}>
        <Text style={styles.subHeader}>Enter oz amount</Text>
        <NumericInput
          value={ozValue}
          onChange={(ozValue) => setOzValue(ozValue)}
          minValue={0}
          totalWidth={150}
          totalHeight={35}
          iconSize={35}
          step={0.5}
          valueType="real"
          rounded
          textColor="black"
          rightButtonBackgroundColor={Colors[colorScheme].tabIconSelected}
          leftButtonBackgroundColor={"#a57ee0"}
          iconStyle={{
            color: "white",
            fontSize: 20,
            fontWeight: "bold",
          }}
        />
      </View>
      <View style={styles.numInputContainer}>
        <Text style={styles.subHeader}>Enter duration</Text>
        <NumericInput
          value={minuteValue}
          minValue={0}
          onChange={(minuteValue) => setMinuteValue(minuteValue)}
          totalWidth={150}
          totalHeight={35}
          iconSize={35}
          step={1}
          valueType="real"
          rounded
          textColor="black"
          rightButtonBackgroundColor={Colors[colorScheme].tabIconSelected}
          leftButtonBackgroundColor={"#a57ee0"}
          iconStyle={{
            color: "white",
            fontSize: 20,
            fontWeight: "bold",
          }}
        />
      </View>
      <View style={styles.buttonContainer}>
        <Button
          color={Colors[colorScheme].tabIconSelected}
          mode="contained"
          onPress={onSubmit}
          disabled={disabled()}
        >
          Add
        </Button>
        <Button
          color={Colors[colorScheme].tabIconSelected}
          mode="contained"
          disabled={disabled()}
          onPress={onSubmitNext}
        >
          Add&Next
        </Button>
        <Button mode="contained" color={"#a57ee0"} onPress={modalClose}>
          Cancel
        </Button>
      </View>
    </KeyboardAwareScrollView>
  );
}

Expected behavior
I expect the values to reset back to 0 on state change.

Screenshots or Screen recording
Capture

@EHRdev
Copy link

EHRdev commented May 18, 2023

I also went through the same thing, the component doesn't render to the parent like a does.

I recommend another similar package, updated with on hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants