import React, { ReactNode, createContext, useContext } from 'react' import type { AssetFromSource } from '@sanity/types' type ContextProps = { onSelect?: (assetFromSource: AssetFromSource[]) => void } type Props = { children: ReactNode onSelect?: (assetFromSource: AssetFromSource[]) => void } const AssetSourceDispatchContext = createContext( undefined ) export const AssetBrowserDispatchProvider = (props: Props) => { const { children, onSelect } = props const contextValue: ContextProps = { onSelect, } return ( {children} ) } export const useAssetSourceActions = () => { const context = useContext(AssetSourceDispatchContext) if (context === undefined) { throw new Error( 'useAssetSourceActions must be used within an AssetSourceDispatchProvider' ) } return context } export default AssetSourceDispatchContext