Skip to content

Make custom store feature as singleton #4716

Discussion options

You must be logged in to vote

Well, in that case

export function withQuizStore() {
  return signalStoreFeature(
    withProps(() => ({ quizStore: inject(QuizStore) })),
    withComputed((state) => ({
      score: state.quizStore.score,
      title: state.quizStore.title,
      /// add other signals here...
    }))
  );
}

export const OtherStore = signalStore(
  withQuizStore(),
  withHooks((store) => ({
    onInit() {
      console.log(store.title());
    },
  }))
);

I don't think it happens that often, that a local store wants to patch through data from the global store 1:1. What is your opinion on that?

Another alternative would be that your component is working with both global and local store.

Replies: 4 comments 12 replies

Comment options

You must be logged in to vote
2 replies
@BarakDabach
Comment options

@BarakDabach
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@rainerhahnekamp
Comment options

@BarakDabach
Comment options

@BarakDabach
Comment options

@rainerhahnekamp
Comment options

Answer selected by BarakDabach
@BarakDabach
Comment options

@rainerhahnekamp
Comment options

@BarakDabach
Comment options

Comment options

You must be logged in to vote
1 reply
@BarakDabach
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4715 on March 06, 2025 14:40.