Answer the question
In order to leave comments, you need to log in
How to add a class to an element from another component?
Here is the first file:
<div className="form__item">
<NameInput refNameInput={this.nameInput} />
</div>
export default class NameInput extends React.Component<MyType> {
constructor(props: MyType) {
super(props);
}
render() {
return (
<>
<label htmlFor="formName" className="form__label">
Name:
</label>
<input
ref={this.props.refNameInput}
minLength={4}
type="text"
id="formName"
name="name"
className="form__input"
/>
</>
);
}
}
Answer the question
In order to leave comments, you need to log in
The parent is the first file, I import the second in 1
<div className={isError ? 'error' : '')}>
<div style={errorClassStyles}>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question