Skip to content

Commit b0fff59

Browse files
authored
Change createSlots to use layout effects instead of regular effects
1 parent b78170c commit b0fff59

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/utils/create-slots.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import {useForceUpdate} from './use-force-update'
3+
import useLayoutEffect from './useIsomorphicLayoutEffect'
34

45
/** createSlots is a factory that can create a
56
* typesafe Slots + Slot pair to use in a component definition
@@ -42,7 +43,7 @@ const createSlots = <SlotNames extends string>(slotNames: SlotNames[]) => {
4243
const [isMounted, setIsMounted] = React.useState(false)
4344

4445
// fires after all the effects in children
45-
React.useEffect(() => {
46+
useLayoutEffect(() => {
4647
rerenderWithSlots()
4748
setIsMounted(true)
4849
}, [rerenderWithSlots])
@@ -86,7 +87,7 @@ const createSlots = <SlotNames extends string>(slotNames: SlotNames[]) => {
8687
> = ({name, children}) => {
8788
const {registerSlot, unregisterSlot, context} = React.useContext(SlotsContext)
8889

89-
React.useEffect(() => {
90+
useLayoutEffect(() => {
9091
registerSlot(name, typeof children === 'function' ? children(context) : children)
9192
return () => unregisterSlot(name)
9293
}, [name, children, registerSlot, unregisterSlot, context])

0 commit comments

Comments
 (0)