mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-07 22:41:59 +08:00
docs(use-current-state): add docs for functional initializer mode
fix(dropdown): update layout when mouseenter triggered
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { MutableRefObject, useState } from 'react'
|
||||
import React, { MutableRefObject, useEffect, useState } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import usePortal from '../utils/use-portal'
|
||||
import useResize from '../utils/use-resize'
|
||||
@@ -57,6 +57,15 @@ const Dropdown: React.FC<React.PropsWithChildren<Props>> = React.memo(
|
||||
useDOMObserver(parent, () => {
|
||||
updateRect()
|
||||
})
|
||||
useEffect(() => {
|
||||
if (!parent || !parent.current) return
|
||||
parent.current.addEventListener('mouseenter', updateRect)
|
||||
/* istanbul ignore next */
|
||||
return () => {
|
||||
if (!parent || !parent.current) return
|
||||
parent.current.removeEventListener('mouseenter', updateRect)
|
||||
}
|
||||
}, [parent])
|
||||
|
||||
const clickHandler = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||
event.stopPropagation()
|
||||
|
||||
@@ -46,7 +46,7 @@ type CurrentStateType<S> = [
|
||||
]
|
||||
|
||||
const useCurrentState<S> = (
|
||||
initialState: S,
|
||||
initialState: S | () => S,
|
||||
) => CurrentStateType<S>
|
||||
```
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ type CurrentStateType<S> = [
|
||||
]
|
||||
|
||||
const useCurrentState<S> = (
|
||||
initialState: S,
|
||||
initialState: S | () => S,
|
||||
) => CurrentStateType<S>
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user