'TypeError: getTodosFromUserDevice is not a function Also TypeError: saveTodoToUserDevice is not a function

I have created a todo list and it works fine, but I need to add async storage to store the todo list when the page refreshes, or closes etc. So, I added async storage, but when I added React.useEffect it shows TypeError: getTodosFromUserDevice is not a function and TypeError: saveTodoToUserDevice is not a function

I have added two functions:

  1. getTodosFromUserDevice
  2. saveTodoToUserDevice

React UseEffect Code:

React.useEffect(() => {
    getTodosFromUserDevice;
}, []);

React.useEffect(() => {
    saveTodoToUserDevice(todos);
}, [todos]);

My The Function I gave:

const saveTodoToUserDevice = async todos => {
  try {
    const stringifyTodos = JSON.stringify(todos);
      await AsyncStorage.setItem('todos', stringifyTodos);
    } catch (error) {
      console.log(error);
  }
};

const getTodosFromUserDevice = async () => {
  try {
    const todos = await AsyncStorage.getItem('todos');
    if (todos != null) {
      setTodos(JSON.parse(todos));
    }
  } catch (error) {
    console.log(error);
  }
};

I hope someone can help me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source