Skip to content

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

Description

@verbowersock

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions