0
I would like to know the best way to start rendering this first object and when you click on the checkbox it will render the next one, hiding the previous one and so on.
const [expensesData, setExpensesData] = useState([
{
position: 0,
label: 'Descrição',
show: true,
value: '',
},
{
position: 1,
label: 'Valor',
show: false,
value: '',
},
{
position: 2,
label: 'Categoria',
show: false,
value: '',
},
{
position: 3,
label: 'Data',
show: false,
value: '',
},
{
position: 4,
label: 'Pago com',
show: false,
value: '',
},
{
position: 5,
label: 'Repete',
show: false,
value: '',
},
{
position: 6,
label: 'Pago',
show: false,
value: '',
},
]);
const handleShowNextOption = useCallback(
index => {
console.log(index);
},
[expensesData],
);
return (
<>
<Container>
<Header />
<Form ref={formRef} onSubmit={handleSubmit}>
<OptionsContainer>
{expensesData.map((item, index) => (
<>
{item.position === index && item.show && (
<OptionItem>
<span>{item?.label}</span>
<Input name="description" type="text" value={item?.value} />
<input
type="checkbox"
onClick={() => handleShowNextOption(index)}
/>
</OptionItem>
)}
</>
))}
</OptionsContainer>
</Form>
</Container>
</>
);
};