'REACT Multi steps form : Next button doesn't work and first circle already in green
I'm beginner in REACT and I'm trying to create a multi steps form in React. How do I hide the BACK button for the first page (see the picture please).
export default function StepperControl({ handleClick, currentStep, steps }) {
return (
<div className="container mt-4 mb-8 flex justify-around">
<button
onClick={() => handleClick()}
className={`cursor-pointer rounded-xl border-2 border-slate-300 bg-white py-2 px-4 font-semibold uppercase text-slate-400 transition duration-200 ease-in-out
hover:bg-slate-700 hover:text-white ${currentStep === 1 ? " cursor-not-allowed opacity-50 " : ""
}`}
>
Back
</button>
<button
onClick={() => handleClick("next")}
className="cursor-pointer rounded-lg bg-blue-700 py-2 px-4 font-semibold uppercase text-white transition duration-200 ease-in-out hover:bg-slate-700 hover:text-white"
>
{currentStep === steps.length - 1 ? "Confirm" : "Next"}
</button>
</div>
);
}
Many thanks for your help
Solution 1:[1]
I guess this is what you need.
export default function StepperControl({ handleClick, currentStep, steps }) {
return (
<div className="container mt-4 mb-8 flex justify-around">
{
currentStep > 1 &&
<button
onClick={() => handleClick()}
className={`cursor-pointer rounded-xl border-2 border-slate-300 bg-white py-2 px-4 font-semibold uppercase text-slate-400 transition duration-200 ease-in-out
hover:bg-slate-700 hover:text-white cursor-not-allowed opacity-50`}
>
Back
</button>
}
<button
onClick={() => handleClick("next")}
className="cursor-pointer rounded-lg bg-blue-700 py-2 px-4 font-semibold uppercase text-white transition duration-200 ease-in-out hover:bg-slate-700 hover:text-white"
>
{currentStep === steps.length - 1 ? "Confirm" : "Next"}
</button>
</div>
);
}
Also, you should send currentStep as a number/integer, not as an object.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | c0drut |

