Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Error: Can not pass the third param when this class extends the other #3739

Closed
Highnesslin opened this issue Jul 31, 2023 · 3 comments
Closed
Labels

Comments

@Highnesslin
Copy link

class Base {
  history = []

  constructor() {
    makeObservable(
      this,
      {
        history: observable,
      },
      {
        deep: false,
      }
    )
  }
}

class Timer extends Base {
  secondsPassed = 0

  constructor() {
    super()
    makeObservable(
      this,
      {
        secondsPassed: observable,
        increaseTimer: action.bound,
      },
      {
        deep: false,
      }
    )
  }

  increaseTimer() {
    this.secondsPassed += 1
  }
}

Intended outcome:

no error

Actual outcome:

Uncaught Error: [MobX] Options can't be provided for already observable objects.

How to reproduce the issue:

The above code

Versions

6.10.0
@kubk
Copy link
Collaborator

kubk commented Jul 31, 2023

Please read about the inheritance limitations in Mobx: https://mobx.js.org/subclassing.html#limitations

@mweststrate
Copy link
Member

mweststrate commented Jul 31, 2023 via email

@Highnesslin
Copy link
Author

You can use observable.shallow instead on each property instead of deep:false

On Mon, 31 Jul 2023, 10:08 Egor Gorbachev, @.> wrote: Please read about the inheritance limitations in Mobx: https://mobx.js.org/subclassing.html#limitations — Reply to this email directly, view it on GitHub <#3739 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBCZHEJOHEFTLHUHW5DXS5RZLANCNFSM6AAAAAA253O22Q . You are receiving this because you are subscribed to this thread.Message ID: @.>

👏It's worked,Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants