parent
f87379fa98
commit
fb16016ad0
3 changed files with 30 additions and 0 deletions
@ -0,0 +1,26 @@ |
||||
import { MutableRefObject } from 'react'; |
||||
|
||||
import { MessageGroupForwardedRefContent } from '../components/MessageGroup'; |
||||
|
||||
type BuildMapToMessageSetterReturnType<T extends MapToInputTestID> = { |
||||
[MessageSetterID in keyof T]: MessageSetterFunction; |
||||
}; |
||||
|
||||
const buildMapToMessageSetter = <T extends MapToInputTestID>( |
||||
mapToID: T, |
||||
messageGroupRef: MutableRefObject<MessageGroupForwardedRefContent>, |
||||
): BuildMapToMessageSetterReturnType<T> => |
||||
Object.entries(mapToID).reduce<BuildMapToMessageSetterReturnType<T>>( |
||||
(previous, [key, id]) => { |
||||
const setter: MessageSetterFunction = (message?) => { |
||||
messageGroupRef.current.setMessage?.call(null, id, message); |
||||
}; |
||||
|
||||
previous[key as keyof T] = setter; |
||||
|
||||
return previous; |
||||
}, |
||||
{} as BuildMapToMessageSetterReturnType<T>, |
||||
); |
||||
|
||||
export default buildMapToMessageSetter; |
@ -0,0 +1 @@ |
||||
type MapToInputTestID = { [key: string]: string }; |
@ -0,0 +1,3 @@ |
||||
type MessageSetterFunction = ( |
||||
message?: import('../components/MessageBox').Message, |
||||
) => void; |
Loading…
Reference in new issue