Answer the question
In order to leave comments, you need to log in
How to show items one by one in React?
Hello everyone
It turns out, I need the following logic:
When I added a new element to the base, I hide <div/>
with this element and generate (or show a ready one? ). How can this be implemented?
Example:
I went to the site, I have a form in front of me: enter the first and last name. Entered, the form disappeared, another one opened, where you need to enter the date of birth and place of residence.
Need something like this
Thanks
Answer the question
In order to leave comments, you need to log in
Make two shapes. Listen to submit. By submitting the first form - change the state - hide the first form and show the second form.
Everything is solved by regular means of react.
It could be something like this:
render() {
const isUserInfoFormActive = ...; // your conditions
const isUserAddressFormActive = ...; // your conditions
return (
<Wrapper>
{isUserInfoFormActive && <UserInfoForm />}
{isUserAddressFormActive && <UserAddressForm />}
</Wrapper>
);
}
class FormWidget extends Component {
...
getContent() {
const { children, activeStep } = this.props;
return React.Children.map(children, (child, i) => {
if (activeStep === i + 1) {
return React.cloneElement(child, { key: i });
}
return null;
});
}
handleNext = () => {
...
};
handlePrev = () => {
...
};
render() {
...
return(
<div>
<Content>{this.getContent()}</Content>
<div>
<Button onClick={this.handlePrev}>{prevButtonLabel}</Button>
<Button onClick={this.handleNext}>{nextButtonLabel}</Button>
</div>
</div>
);
}
}
render() {
return (
<FormWidget>
<Step1 />
<Step2 />
<Step3 />
<Step4 />
<Step5 />
<Step6 />
<Step7 />
<Step8 />
<Step9 />
<Step10 />
</FormWidget>
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question