score:1

Accepted answer

Use prev parameter in useState hook. The useState hook is asynchronous.

const updateTranslatedResponse = (segmentId, key, value) => {
    setTranslatedResponse( prevTranslatedResponse =>
        prevTranslatedResponse.map(
            el => el.segment_id == segmentId ? { ...el, [key]: value }: el
        )
    )
}

Related Query

More Query from same tag