I got the following components
|-- App
|-- Components
|-- WidgetMenu
|-- Editor
I want to place WidgetMenu component in 3 locations in App as below.
.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-template-rows: 2fr 1fr;
grid-template-areas:
"left center right"
"bottom bottom bottom";
height: 100vh;
}
.left {
grid-area: left;
background: green;
color: white;
}
.right {
grid-area: right;
background: green;
color: white;
}
.bottom {
grid-area: bottom;
background: green;
color: white;
}
.center {
grid-area: center;
}
.container > div {
border: 2px solid black;
}
<div class="container ">
<div class="left">WidgetMenu Left</div>
<div class="right">WidgetMenu Right</div>
<div class="bottom">WidgetMenu Bottom</div>
<div class="center">Editor</div>
</div>
To do that, I'm using css class as follows.
render() {
return (
<div className="App">
<WidgetMenu className="left" />
<WidgetMenu className="right" />
<WidgetMenu className="bottom" />
<Editor className="center" />
</div>
);
}
But I can not pass a className because there is no such property requested by WidgetMenu. So how this should be done? What would be the proper way? Do I have to wrap every react component by divs and use className on them?
classNameaspropsto theWidgetMenu?<WidgetMenu classToApply={"left"} />className:)Appcomponent byApp.cssstyle sheet. There is no real use of the class name insideWidgetMenu. That's why I want to know if there is any other way.classNameon a component because it has no DOM, so you have a DOM element to apply the class on. But you can split the code. The parent (App) will contains the styles which relevant to it and in Widget.css put the styles which relevant to the widgets..classNamereact just take it as a regular prop value.<WidgetMenu className="left" />