Creating custom SolidJS hook that can be used in a global scope

Need some help understanding how to build a custom SolidJS hook that can be used both locally inside a component and outside in the global scope (like
createSignal
can).

Below is. a small snippet of a custom hook I am writing:

export function createDatabase(dbOrName?: string | Database, config: ConfigOpts = {}): CreateDatabase {

  const database = createMemo(() => (isDatabase(dbOrName) ? dbOrName : genDb(dbOrName || "DefaultDB", config)));

return { database }


The question I have is around the floating
createMemo
that I use in the implementation. When I use the
createDatabase
hook globally, I get greeted with the console warning:

computations created outside a 'createRoot' or 'render' will never be disposed


I'm not familiar with how to properly address that warning and hoping the community can offer some guidance here.
Was this page helpful?