From 971dcd7492a2b2fa4a8f5938101ef0f85b408fac Mon Sep 17 00:00:00 2001 From: unix Date: Sun, 24 May 2020 01:55:36 +0800 Subject: [PATCH] docs(use-current-state): add docs for functional initializer mode fix(dropdown): update layout when mouseenter triggered --- components/shared/dropdown.tsx | 11 ++++++++++- pages/en-us/components/use-current-state.mdx | 2 +- pages/zh-cn/components/use-current-state.mdx | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/shared/dropdown.tsx b/components/shared/dropdown.tsx index dc36063..b8442cb 100644 --- a/components/shared/dropdown.tsx +++ b/components/shared/dropdown.tsx @@ -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.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) => { event.stopPropagation() diff --git a/pages/en-us/components/use-current-state.mdx b/pages/en-us/components/use-current-state.mdx index e234533..100ee76 100644 --- a/pages/en-us/components/use-current-state.mdx +++ b/pages/en-us/components/use-current-state.mdx @@ -46,7 +46,7 @@ type CurrentStateType = [ ] const useCurrentState = ( - initialState: S, + initialState: S | () => S, ) => CurrentStateType ``` diff --git a/pages/zh-cn/components/use-current-state.mdx b/pages/zh-cn/components/use-current-state.mdx index 559fa16..ccd11bf 100644 --- a/pages/zh-cn/components/use-current-state.mdx +++ b/pages/zh-cn/components/use-current-state.mdx @@ -44,7 +44,7 @@ type CurrentStateType = [ ] const useCurrentState = ( - initialState: S, + initialState: S | () => S, ) => CurrentStateType ```