|
|
@ -19,6 +19,7 @@ type MessageGroupOptionalProps = { |
|
|
|
type MessageGroupProps = MessageGroupOptionalProps; |
|
|
|
type MessageGroupProps = MessageGroupOptionalProps; |
|
|
|
|
|
|
|
|
|
|
|
type MessageGroupForwardedRefContent = { |
|
|
|
type MessageGroupForwardedRefContent = { |
|
|
|
|
|
|
|
exists?: (key: string) => boolean; |
|
|
|
setMessage?: (key: string, message?: Message) => void; |
|
|
|
setMessage?: (key: string, message?: Message) => void; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -36,6 +37,10 @@ const MessageGroup = forwardRef< |
|
|
|
) => { |
|
|
|
) => { |
|
|
|
const [messages, setMessages] = useState<Messages>({}); |
|
|
|
const [messages, setMessages] = useState<Messages>({}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const exists = useCallback( |
|
|
|
|
|
|
|
(key: string) => messages[key] !== undefined, |
|
|
|
|
|
|
|
[messages], |
|
|
|
|
|
|
|
); |
|
|
|
const setMessage = useCallback((key: string, message?: Message) => { |
|
|
|
const setMessage = useCallback((key: string, message?: Message) => { |
|
|
|
setMessages((previous) => { |
|
|
|
setMessages((previous) => { |
|
|
|
const result = { ...previous }; |
|
|
|
const result = { ...previous }; |
|
|
@ -67,7 +72,10 @@ const MessageGroup = forwardRef< |
|
|
|
[defaultMessageType, messages], |
|
|
|
[defaultMessageType, messages], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
useImperativeHandle(ref, () => ({ setMessage }), [setMessage]); |
|
|
|
useImperativeHandle(ref, () => ({ exists, setMessage }), [ |
|
|
|
|
|
|
|
exists, |
|
|
|
|
|
|
|
setMessage, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
return <>{messageElements}</>; |
|
|
|
return <>{messageElements}</>; |
|
|
|
}, |
|
|
|
}, |
|
|
|