Question: I'm new to React. I have two button for sort. But I want to change for sort both ascending and descending in one button.

```
 // sort asc
  const onSortA = (e) => {
    let uname = [...userdata];

    switch (e.target.id) {
      case "name":
        uname = uname.sort((a, b) => a.name - b.name);
        break;
      default:
    }
  };

  // sort desc
  const onSortD = (e) => {
    let uname = [...userdata];

    switch (e.target.id) {
      case "name":
        uname = uname.sort((a, b) => a.name - b.name);
        uname.reverse();
        break;   
      default:
    }
  };

```

Answer: 
If you want to update your state (that is an array) in react hooks, you should try like this :

```
  const new_todo = (input) => set_todos(oldState => [...oldState,input])

```

with this code, you will not see any error but I have some offer for your code that make it better:

* put your inputs such as input and buttons in the form tag
* use variable declarations outside of return ( let return be for HTML tag and its better to use your logics outside of return ) make it easier to read

and I think your code can be like this:

```
import React, { useState } from 'react'

export default function App() {
  const [todos , set_todos] = useState([''])
  const submitTask = (e) =>{

    // Calling preventDefault() during any stage of event flow cancels the event,
    // meaning that any default action normally taken by the implementation
    // as a result of the event will not occur
    e.preventDefault(); 

    const { taskInput } = e.target; // get your input by name

    // assign input value to your state
    set_todos(oldState => [...oldState, taskInput.value ]) 
  }
  return (
    <>
      <h1>hello world</h1>
      <form onSubmit={submitTask}>
        <input name="taskInput" />
        <button type="submit">add todo</button>
      </form>

      <ul>
        {todos.map(todo =>(
          <li>{todo}</li>
        ))}
      </ul>

    </>
  )
}

```
You should use `set_todos` like below:

```
set_todos([...todos, input]);

```

Because `set_todos` is a function. You can find the State Hook's usage in [Introducing Hooks](https://reactjs.org/docs/hooks-state.html).