Skip to content

Commit

Permalink
fix: synchronously reading regionId initial value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ícaro committed Sep 23, 2021
1 parent 91f4044 commit 1dc995c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/gatsby-theme-store/src/sdk/region/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ export interface IContext {
export const Context = createContext<IContext | undefined>(undefined)

export const Provider: FC = ({ children }) => {
const [postalCode, setPostalCode] = useState<Maybe<string>>(null)
const [regionId, setRegionId] = useState<Maybe<string>>(null)
const [isLoading, setLoading] = useState(true)

const [postalCode, setPostalCode] = useState<Maybe<string>>(
controller.postalCode.get()
)

const [regionId, setRegionId] = useState<Maybe<string>>(
controller.region.get()
)

const value = useMemo(
() => ({
postalCode,
Expand All @@ -36,8 +42,6 @@ export const Provider: FC = ({ children }) => {
)

useEffect(() => {
setPostalCode(controller.postalCode.get())
setRegionId(controller.region.get())
setLoading(false)
}, [])

Expand Down

0 comments on commit 1dc995c

Please sign in to comment.