K
K
Kirr072021-10-06 15:40:39
React
Kirr07, 2021-10-06 15:40:39

How can I change the background color to the user's choice?

There is a list with a set of colors (array: red, blue, etc.) and a paragraph. How can I make the background change when choosing a color?

If there is any good documentation with examples for beginners, I would be grateful for the link.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Dvoryanov, 2021-10-06
@Raxen

If you don’t have a question about how the user selects a color, then you are familiar with this part of the development, so you take the color value selected by the user (for example, the userColor variable) and put it, for example, in the useEffect hook

useEffect(() => {
  document.body.style.backgroundColor = userColor;
}, [userColor]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question