How to use setState in React

Issue #662

Use spread operator

1
2
3
4
5
6
7
8
9
10
11
12
13
import React, { Component, useState, useEffect } from 'react';

const [state, setState] = useState({
message: '',
chats: [],
sending: false
})

setState(prevState => ({
...prevState,
message: '',
sending: false
}))

Comments