Answer the question
In order to leave comments, you need to log in
How to replace one component with another on click in React?
Hello everyone, I have two different blocks:
<div className='first'>
<div>
<div>Login</div>
<div><a href="#" className='reg'>or Register</a></div>
</div>
<div>
<input type="text">
<input type="text">
<button>Войти</button>
<div>
</div>
<div className='second'>
<div>
<div>Register</div>
<div><a href="#" className='log'>or Login</a></div>
</div>
<div>
<input type="text">
<input type="text">
<input type="text">
<button>Зарегистрироваться</button>
<div>
</div>
Answer the question
In order to leave comments, you need to log in
Make them into separate components and conditionally render.
Rough, like this
I strongly recommend that before writing anything of your own, study the library and its capabilities better, since you do not know its basic concepts. Read about state management and conditional rendering, or rather the entire manual from cover to cover.
class Example extends Component {
state = {
activeForm: 'login',
};
setActiveForm = name => {
this.setState({ activeForm: name });
};
render() {
const Form = this.state.activeForm === 'login' ? Login : Registration;
return (
<SideBar>
<Form setActiveForm={setActiveForm} />
</SideBar>
);
}
}
https://github.com/ReactTraining/react-router
https://github.com/reach/router
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question