#useState one step behind onChange

2 messages · Page 1 of 1 (latest)

gilded willow
#

Having an issue where my state is one step behind where it should be. I've googled this and see that it's because it's asynchronous, but can't figure out how to solve the issue. Can anyone help? Thanks!

#
      xsetSelectedSeat(id)
    }

    return (
        <Wrapper>
            {seating && seating.length > 0 ? (
                seating.map((seat) => (
                    <SeatWrapper key={`seat-${seat.id}`}>
                        <label>
                            {seat.isAvailable ? (
                                <>
                                    <Seat type="radio" 
                                          name="seat" 
                                          onChange={() => handleChange(seat.id)}/>
                                    <Available>{seat.id}</Available>
                                </>
                            ) : (
                                <Unavailable>{seat.id}</Unavailable>
                            )}
                        </label>
                    </SeatWrapper>
                ))
            ) : (
                <Placeholder>Select a Flight to view seating.</Placeholder>
            )}
        </Wrapper>```