1
Hello, everyone. I’m using the library Vibrantjs passing an array of images and saving the return in the state of my component in React. As in the code snippet below.
gerarPaleta = () => {
let imagens = this.state.imagens;
let paletaTemp = [];
for (let i in imagens) {
Vibrant.from(imagens[i].src.small).getPalette()
.then((palette) =>
paletaTemp.push({
id: i,
paleta: palette
})
);
}
this.setState({ paletas: paletaTemp });
console.log('Paletas: ', this.state.paletas);
}
The problem is that I can’t access the state data paletas
. Because it returns a warning in the browser console
Value Below was evaluated just now.
And it appears in this structure:
And what I want is to render the color in a div:
render() {
...
let paletas = this.state.paletas;
...
<div className="container">
{paletas.map((paleta, index) => (
<div className="row">
<div className="col-sm paleta" style={{background: paletas.paleta.DarkMuted.hex }}>
</div>
</div>
))}
</div>
...
}
But the map
does not run at any time, because the array is "empty".
I appreciate anyone who can help me. :)