Skip to content

请教umi如何使用mobx?使用装饰器语法+mobx HOC,目前看起来无法正常触发渲染。 #11947

Answered by fz6m
Snorlaxx-plot asked this question in Q&A
Discussion options

You must be logged in to vote

以下是我可以运行的示例:

  pnpm add tslib
// tsconfig.json
{
  "extends": "./src/.umi/tsconfig.json",
  "compilerOptions": {
+   "experimentalDecorators": true,
+   "emitDecoratorMetadata": true
  }
}
// index.ts

import { observer } from 'mobx-react-lite'
import { counterStore } from './store'

const Page = observer(({ counter }: { counter: typeof counterStore }) => {
  return (
    <div>
      {counter.count}
      <button
        onClick={() => {
          counter.increment()
        }}
      >
        +
      </button>
    </div>
  )
})

export default function C() {
  return <Page counter={counterStore} />
}
// store.ts

import { makeObservable, observable, action } from 'mobx'

class Counter {
  @

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Snorlaxx-plot
Comment options

@fz6m
Comment options

Answer selected by Snorlaxx-plot
@Snorlaxx-plot
Comment options

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