DEV Community

create a reservasion section

Ali Ibrahim on January 03, 2023

Hello everyone im learning react right now i was building a section for a project which is reservation section but i get stuck and need some hint ...
Collapse
 
tanmoysarkar profile image
Tanmoy Sarkar

You can manage it by useState easily.
I assume , you have section 1, section 2, section 3 .....
When someone submit section 1 going to section 2

In a useState you can store the state number and when someone submitting it can update its state , You can do it by simple if else.

const [currentSection, setCurrentSectionNo] = useState(1);

function submitProcess(){
     // do whatever your logic for submission or storing records
    // if that succed call
   setCurrentSectionNo(currentSection+1);
}

return (
<>
{  currentSection == 1 ? <Component_1 onClick={submitProcess} /> :
currentSection == 2 ? <Component_2 onClick={submitProcess} /> :
currentSection == 3 ? <Component_3 onClick={submitProcess} /> :
<div></div> }
</>
);

Enter fullscreen mode Exit fullscreen mode

It's most simple way to do it. You can do it also in better way, to make the code more clean.

Collapse
 
bluesky1992web profile image
Ali Ibrahim

Thank you very much @tanmoysarkar it was really helpful