Answer the question
In order to leave comments, you need to log in
How to register classes in css modules depending on the condition (React)?
Hello.
I have a react project. The appointments component has a parent block without styles.
I want to use this component in two different places (components) with different styles depending on where it is called. What is the best way to implement this? Or tell me where to read.
for a better explanation:
The appointments component:
Condition: if this is the LastAppointments component, then the ROW class is applied to the block, if it is the AllAppointments component, then the COLUMN class.
<div className={Row или Column}> какой то код </div>
Answer the question
In order to leave comments, you need to log in
You can do without extra states.
That is, you pass its name to the props of the component (well, or any other identifier)
<LastAppointments name={'LastAppointments'} />
<div className={ props.name == 'LastAppointments' ? 'row' : 'column' }> какой то код </div>
create
[state, setState] = useState(false) change
it as needed
<div className={ state ? "row" : "column"}> какой то код </div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question