Skip to content

Redundant provideContext function with createTrinity #185

@KaelWD

Description

@KaelWD

These all have a function that just assigns a default context when createTrinity already does that

(_context: Z = context, app?: App): Z => provideContext(_context, app),

export function createMyFeature<E extends MyContext = MyContext>() {
  const [useContext, _provideContext] = createContext<E>('my-context')

  const context = { foo: 'hello', bar: 42 }

  function provideContext (_context: E = context, app?: App): E {
    return _provideContext(_context, app)
  }

  return createTrinity<E>(useContext, provideContext, context)
}

Instead of just

export function createMyFeature() {
  const [useContext, provideContext] = createContext<MyContext>('my-context')

  const context = { foo: 'hello', bar: 42 }

  return createTrinity<MyContext>(useContext, provideContext, context)
}

useContext and provideContext are only ever passed directly to createTrinity too, why not just

export function createMyFeature() {
  const context = { foo: 'hello', bar: 42 }

  return createTrinity<MyContext>('my-context', context)
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions