Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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]
  }));
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #typescript #append #array
ADD COMMENT
Topic
Name
6+3 =