keajs / kea

Batteries Included State Management for React

Home Page:https://keajs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to use generics with `MakeLogicType` ?

JasonStoltz opened this issue · comments

Something like:

type SomeLogicType<ItemType> = MakeLogicType<
  SomeLogicValues<ItemType>,
  SomeLogicActions<ItemType>
>;

export const SomeLogic = kea<SomeLogicType<ItemType>>({

Where ItemType is passed as a type parameter to useValues or something?

useValues<MyType>(SomeLogic)

I just wrapped it in a factory function and 👌

export const getSomeLogic = <T>() => {
  return kea<SomeLogicType<T>>({
const logic = getSomeLogic<Foo>()();

That's a clever trick!

Not sure why it doesn't work for you though.

Screenshot 2021-07-23 at 21 29 27

image

That does work. Sorry, to clarify, instead of a concrete type like ItemType in your example, I want it to be generic. So that the logic can work with any type. So one place where the logic is used it might work with strings, other places might work with numbers, etc.