0
I’m consuming an API, and putting your data in a 'li', only it’s popping the page because I mapped all the api items:
function showState(states){
return states.map(state => <li key={state.nome}>{state.nome} - {state.sigla}</li>)
}
...
<div className="center">
<ul>
{response.data? showState(response.data): response.err}
</ul>
</div>
The idea would be that the return of the showState function would generate something like, but dynamically, limiting 9 'li' by 'ul':
<ul>
<li>key={state[0].nome}>{state[0].nome} - {state[0].sigla}</li>
<li>key={state[1].nome}>{state[1].nome} - {state[1].sigla}</li>
<li>key={state[2].nome}>{state[2].nome} - {state[2].sigla}</li>
...
<li key={state[8].nome}>{state[8].nome} - {state[8].sigla}</li>
</ul>
<ul>
<li>key={state[9].nome}>{state[9].nome} - {state[9].sigla}</li>
<li>key={state[10].nome}>{state[10].nome} - {state[10].sigla}</li>
<li>key={state[11].nome}>{state[11].nome} - {state[11].sigla}</li>
...
<li key={state[16].nome}>{state[16].nome} - {state[16].sigla}</li>
</ul>
<ul>
<li>key={state[17].nome}>{state[17].nome} - {state[17].sigla}</li>
<li>key={state[18].nome}>{state[18].nome} - {state[18].sigla}</li>
<li>key={state[19].nome}>{state[19].nome} - {state[19].sigla}</li>
...
<li key={state[26].nome}>{state[26].nome} - {state[26].sigla}</li>
</ul>
It worked well friend, thanks! The idea was to do something more dynamic (without having to create the <ul>) but I’ll learn over time kkkk. A question if I want to leave the
const filteredStates
out of functionshowState
i would have to create the variables indexStart and indexLimit and change them byuseState()
right? And in case I passed theconst filteredStates
as an argument to functionshowState()
and also the arguments ofindexStart
andindexLimit
(in that wayshowState(filteredStates,0,9)
) would the communication between the constant and the other arguments?? (I do not know if I was clear...)– Rafael Pádua Del Corona
No need to re-create the
ul
, you can just render theul
your caseindexStart
either 0 or already leave theul
on the page and return theli
gradually. About theuseState
, that’s right. The idea is to control their state in the component withuseState
and only pass what you want back to function.– Ruan Montelo