mirror of
https://github.com/System-End/site.git
synced 2026-04-20 00:25:19 +00:00
Fix bug with unsynced state on page load
This commit is contained in:
parent
9062fcf7b3
commit
6ebc24c982
1 changed files with 12 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Input, Select, Textarea } from 'theme-ui'
|
||||
import Field from './field'
|
||||
import useOrganizationI18n from '../organizationI18n'
|
||||
|
|
@ -9,6 +9,17 @@ export default function OrganizationAdultForm({ requiredFields }) {
|
|||
|
||||
const onTeenagerLedChange = e => setTeenagerLed(e.target.value)
|
||||
|
||||
useEffect(() => {
|
||||
// [@garyhtou] welp... this exists because the Field component will cache
|
||||
// input values and set them on page load. It does it by directly setting
|
||||
// `input.value` with JavaScript; bypassing React. Because of that, the
|
||||
// `teenagerLed` state may not be synced with the DOM input value. This code
|
||||
// syncs `teenagerLed` with the DOM input value.
|
||||
// NOTE: This depends on Field's useEffect hook to run first.
|
||||
const eventTeenagerLedElm = document.getElementById('eventTeenagerLed')
|
||||
setTeenagerLed(eventTeenagerLedElm.value)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Field
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue