Changeset View
Changeset View
Standalone View
Standalone View
native/search/search-provider.react.js
- This file was added.
// @flow | |||||
import * as React from 'react'; | |||||
kamil: I think you should add new line here | |||||
import type { SetState } from 'lib/types/hook-types.js'; | |||||
export type MessageSearchContextType = { | |||||
kamilUnsubmitted Not Done Inline Actionsdo we consume it somewhere, so that there is a need to export? kamil: do we consume it somewhere, so that there is a need to export? | |||||
inkaAuthorUnsubmitted Done Inline ActionsNo, but even if we don't use it anywhere else we usually export ContexType from a file inka: No, but even if we don't use it anywhere else we usually export ContexType from a file | |||||
+query: string, | |||||
+setQuery: SetState<string>, | |||||
+clearQuery: () => void, | |||||
}; | |||||
const MessageSearchContext: React.Context<?MessageSearchContextType> = | |||||
React.createContext<?MessageSearchContextType>(); | |||||
type Props = { | |||||
+children: React.Node, | |||||
}; | |||||
function MessageSearchProvider(props: Props): React.Node { | |||||
const { children } = props; | |||||
const [query, setQuery] = React.useState<string>(''); | |||||
kamilUnsubmitted Not Done Inline Actionspersonally, I prefer to infer the type from the default argument as for me this redundancy - but this is frequent in the codebase so as you prefer kamil: personally, I prefer to infer the type from the default argument as for me this redundancy… | |||||
const clearQuery = React.useCallback(() => setQuery(''), []); | |||||
const context = React.useMemo( | |||||
() => ({ | |||||
query, | |||||
setQuery, | |||||
clearQuery, | |||||
}), | |||||
[query, clearQuery], | |||||
); | |||||
return ( | |||||
<MessageSearchContext.Provider value={context}> | |||||
{children} | |||||
</MessageSearchContext.Provider> | |||||
); | |||||
} | |||||
export { MessageSearchContext, MessageSearchProvider }; |
I think you should add new line here