react-native setting counter numeric value to asyncStorage and into const value

Viewed 247

I have a counter that is functional, where the up and down buttons count by 1. What I want to do, is make it so that every time the button is pressed and the number changes it saves that number as 'dailyWaterCount' in AsyncStorage.

THe NumericInput is functional:

<NumericInput 
  value={this.state.value} 
  onChange={value => this.setState({value})} 
  onLimitReached={(isMax,msg) => console.log(isMax,msg)}
  maxNumber = {12}
  totalWidth={150} 
  totalHeight={50} 
  iconSize={25}
  step={1}
  valueType='real'
  rounded 
  textColor='#000' 
  iconStyle={{ color: 'white' }} 
  rightButtonBackgroundColor='#4CA1AF' 
  leftButtonBackgroundColor='#C4E0E5'/>

So where I need help is to save the value to dailyWaterCount on every left or right button press and then I need to make it so that my const data holds the given value. In other words if I change the NumericInput from 5 to 4, I want to save 4 as dailyWaterCount and that's what I wantin my const data as well

saveData(){
  let dailyWaterCount = ?;
  AsyncStorage.setItem('dailyWaterCount', dailyWaterCount);
}

displayData = async () => {
  try{
    let user = await AsyncStorage.getItem('user');
  }

  catch(error) {
    alert(error);
  }
}

const data = {
  data: [dailyWaterCount]
};

Any help to fill in these blanks is much appreciated

0 Answers
Related