0

Here is my code, the error occurs under the function saveData.

export default class App extends Component{
  constructor(props){
    super(props);
    this.state = {
      Task: '',
    };
  }

  saveData = () => {
    const {Task} = this.state;

    let myArray={
      Task: Task,
  }
    AsyncStorage.setItem('myArray', JSON.stringify(myArray));
    alert(Task);
  };

  showData = async() => {
    let show = await AsyncStorage.getItem('myArray');
    let ingo = JSON.parse(myArray);
    alert(ingo.Title + '');
  }

  render() {
    return(
          <View>
            <TextInput
              placeholder="Add a Task"
              placeholderTextColor="aqua"
              color="aqua"
              style={styles.textInput}
              onChange={Task => this.setState({Task})}
              onSubmitEditing={this.saveData}
            />
          </View>
      );
    }
  }
smilada
  • 17
  • 6
  • Please try [THIS](https://stackoverflow.com/a/9382383/13378146) first. – Shawn Xiao May 22 '20 at 07:44
  • From your code, it looks like `myArray` is an object `{ Task: Task }` having single property `Task` which has a string as its value. So you should not get this error. Do you have a code playground? – Ajeet Shah May 22 '20 at 15:35

0 Answers0