Skip to content

Instantly share code, notes, and snippets.

@yurtarmehmet
Last active May 10, 2022 08:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurtarmehmet/638f9b3b4be792c00a06cac9efc01a59 to your computer and use it in GitHub Desktop.
Save yurtarmehmet/638f9b3b4be792c00a06cac9efc01a59 to your computer and use it in GitHub Desktop.

State'e yeni item ekleme:

this.setState({
  todos: [...this.state.todos, {
    content: "Yeni Todo",
    completed: false,
    id: Math.random()
  }]
});

State'den item silme:

const silinecekItemId = 12;
this.setState({
  todos: this.state.todos.filter((todo) => {
    return todo.id !== silinecekItemId;
  })
});

State'deki item'i güncelleme:

const guncellenecekItemId = 12;
this.setState({
  todos: this.state.todos.map((todo) => {
      if(todo.id === guncellenecekItemId){
          return {...todo, completed: !todo.completed};
      }else {
          return todo;
      }
  })
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment