Skip to content

Next. js 14 With Mobx #3805

Answered by mawaisismail
mawaisismail asked this question in Q&A
Nov 28, 2023 · 4 comments · 7 replies
Discussion options

You must be logged in to vote

I fount solution for this this is how i implement mobx with next.js 14

store

export class UiStore {
  count = 0;
  constructor() {
    makeAutoObservable(this);
  }

  increment = () => {
    this.count++;
  };
}

group all store

export const RootStore = {
  uiStore,
};

provider

"use client";
import React, { createContext, ReactNode } from "react";
import { RootStore } from "@/store/store";

export const StoreContext = createContext(RootStore);

export const StoreWrapper = ({ children }: { children: ReactNode }) => {
  return (
    <StoreContext.Provider value={RootStore}>{children}</StoreContext.Provider>
  );
};

main layout

  <StoreWrapper>{children}</StoreWrapper>


//hook to get stores

Replies: 4 comments 7 replies

Comment options

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

Answer selected by mawaisismail
Comment options

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

@NileshJain78
Comment options

Comment options

You must be logged in to vote
4 replies
@mawaisismail
Comment options

@ideaviewes
Comment options

@gsi-chao
Comment options

@sungjun-finda
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants