Skip to content

Instantly share code, notes, and snippets.

@guigaoliveira
Last active April 8, 2020 17:22
Show Gist options
  • Save guigaoliveira/9ed50378cf4097f067967a460dc19537 to your computer and use it in GitHub Desktop.
Save guigaoliveira/9ed50378cf4097f067967a460dc19537 to your computer and use it in GitHub Desktop.
const getState = () => ({
labels: [
'Red',
'Green',
'Yellow',
'Surprise'
],
datasets: [{
data: [0, 0, 0, 0],
backgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#ABCDEF'
],
hoverBackgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#ABCDEF'
]
}]
});
this.setState((prevState) => ({
...prevState,
datasets: prevState.datasets.map(obj => {
const [first, ...rest] = obj.data
return ({ ...obj, data: [first + 1, ...rest] })
})
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment