Replies: 2 comments 1 reply
-
|
How/ where do you construct the new User? Not in an action?
…On Tue, Jun 24, 2025, 01:30 Nathan ***@***.***> wrote:
I'm currently migrating our team's tooling to use the new 2022.3
decorators. We have a model that looks like the following:
class User {
@observable accessor username: string;
@observable accessor creationDate: Date | undefined = undefined;
constructor(username: string, creationDate?: Date) {
this.username = username;
this.creationDate = creationDate;
}
}
In our application, we then construct the model using new User(username,
creationDate)
In doing so we get the following error:
[MobX] Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: ***@***.***
Why are we running into this issue? I see a very similar pattern in the
docs <https://mobx.js.org/observable-state.html>
We are using:
- React 18.3.1
- Mobx 6.13.1
- mobx-react 9.1.1
—
Reply to this email directly, view it on GitHub
<#4565>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBGJZL6PLDOWMWK5TA33FCEZDAVCNFSM6AAAAAB76WE3AOVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZYGQ4DMMRQGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Ok, turning that into a flow or (run)inAction should suffice
…On Tue, Jun 24, 2025, 06:08 Nathan ***@***.***> wrote:
We are *not* constructing the user in an action, and we're calling the
constructor from a different context A simplified version of what we're
doing:
async function buildUser() {
let response = await someApiCall();
return new User(response.username, response.date);
}
said async function is in term called from a useEffect in one of our React
components.
—
Reply to this email directly, view it on GitHub
<#4565 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBBYGCZQBA6WWV2YRE33FDFLNAVCNFSM6AAAAAB76WE3AOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJVG4ZDQOI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently migrating our team's tooling to use the new 2022.3 decorators. We have a model that looks like the following:
In our application, we then construct the model using
new User(username, creationDate)In doing so we get the following error:
Why are we running into this issue? I see a very similar pattern in the docs
We are using:
Beta Was this translation helpful? Give feedback.
All reactions