Reputation: 1269
I have a LessonThemes component, which allows you to switch between checkboxes and change the color of the block, the problem is that when importing a component inside the Test component, I do not quite understand how to get the color
value to apply it inside the Test component
LessonThemes.jsx
import React, { useState, useEffect } from "react";
export default function LessonThemes() {
const [color, setColor] = useState(localStorage.getItem("color"));
const [themes, setThemes] = useState([
{ name: "G", color: "green" },
{ name: "R", color: "red" },
{ name: "B", color: "blue" },
])
useEffect(() => {
localStorage.setItem("color", color);
})
const SideBarPageContent = (SideBarPageContentBackground) => {
localStorage.setItem('color', SideBarPageContentBackground);
setColor(SideBarPageContentBackground);
}
return (
<>
{
themes.map((theme, index) => {
return (
<label key={index}>
<input
onChange={() => SideBarPageContent(theme.color)}
type="radio"
name="background"
/>{theme.name}</label>
);
})
}
</>
);
}
Now when importing the LessonThemes component inside the Test component, I need to get the color
value
Lesson.jsx
import React from "react";
export default function Test(props) {
return (
<div style={{background: color}}>
<LessonThemes />
</div>
);
}
Please pay attention to the line of code style={{background: color}}
this code does not work, I just want to show what result I want to achieve and how can I get the value of color
Upvotes: 1
Views: 69
Reputation: 576
I think that you solve the problem that you're having by doing either:
Upvotes: 1