Answers for "react typescript append to array"

0

react typescript append to array

interface IState {
  newTask: string;
  tasks: Array<ITask>;
}

addTask(name:string) {
  const newTask: ITask = {name, done: false}
  this.setState((prevState) => ({
    tasks: [...(prevState.tasks ?? []), newTask]
  }));
}
Posted by: Guest on March-15-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language