We use a modular approach with config files for our react project. So it goes like this:
Component which draws input fields ->
config file which has a parent div and has imported fields file in it ->
fields file which has fields with their IDs, values, etc.
So the question is, how can I select a particular child from the parent div and give it for example col-span-n
?
I want it to look something like this:
grid grid-cols-1 gap-6 md:grid-cols-3 xl:grid-cols-8 mb-6 (and here classnames that will change particular child)
2
Answers
If I understand correctly, you want to apply specific styling or classes to individual children within a parent div based on a modular configuration approach in your React project. One way to achieve this is by passing additional props to the child components and using those props to conditionally apply styles or classes.
Here’s a simplified example to illustrate the concept:
Component:
Config:
ChildComponent:
In this example, the ParentComponent maps over the configuration array and passes the colSpan value to each ChildComponent. The ChildComponent then uses this prop to dynamically set the class for the specific child.
You can customize the configuration based on your specific needs, and this approach allows you to maintain a modular and configurable structure for your React components while still providing flexibility in styling each child independently.
You can try this way: