You can do that way:
setYourObjectInState = () => {
const objectWithNewValues = {
foo: bar,
foo-one: bar-one,
foo-two: bar-two
};
this.setState({
...objectWithNewValues
)};
}
EXAMPLES OF SET STATE + SPREAD OBJECTS USAGE:
Or create an object in your function to reproduce your state and then add the keys with values that you want.
setYourObjectInState = () => {
const yourObjectInState = {
...this.state.yourObjectInState,
foo: bar,
foo-one: bar-one,
foo-two: bar-two
};
this.setState({
yourObjectInState
)};
}
Or you can simply do like
setYourObjectInState = () => {
const yourNewObject = {
foo: bar,
foo-one: bar-one,
foo-two: bar-two
};
this.setState({
yourObjectInState: {
...this.state.yourObjectInState,
...yourNewObject
}
)};
}
or even:
setYourObjectInState = () => {
this.setState({
yourObjectInState: {
...this.state.yourObjectInState,
foo: bar,
foo-one: bar-one,
foo-two: bar-two
}
)};
}
setState()? What are you trying to do?