Using .get() inside a React @observer render function throws an error
See original GitHub issueHi @danielearwicker ,
when I use .get() inside the render() function of an @observer I get an error × Error: promisedComputed must be used inside reactions
. I thought the render function of a React component is also considered an reaction or am I wrong?
Here’s a small example
@observer
class ConnectorTable extends React.Component<Props> {
render() {
const { connectorsStore } = this.props;
const connectors = connectorsStore.connectors.get();
if (!connectors) {
return (
<Loader active size="huge">
Loading Connectors please wait...
</Loader>
);
}
return (
<Page title="Connectors">
<Item.Group>{connectors.map(renderConnector)}</Item.Group>
</Page>
);
}
}
export class ConnectorsStore {
constructor(private _orgStore = orgStore) {}
connectors = promisedComputed(null, async () => {
return fetchConnectors(this._orgStore.selectedOrgId);
});
}
When I use .value
it works as expected (because .value doesn’t do the reaction check), but because .value is private typescript complains about it’s usage.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Getting "Cannot call a class as a function" in my React Project
I got this error because I was using React Router v4 and I accidentally used the render prop instead of the component one...
Read more >React Error Handling and Logging Best Practices
Front-end developers often overlook error handling and logging. However, if any code segment throws an error, you must handle it correctly.
Read more >Test Renderer - React
Find a single descendant test instance with the provided props . If there is not exactly one test instance with the provided props...
Read more >React Query Error Handling | TkDodo's blog
So to make Error Boundaries work in React Query, the library internally catches the error for you and re-throws it in the next...
Read more >React Testing Library and the “not wrapped in act” Errors
In test, the code to render and update React components need to be included in React's call stack. So the test behaves more...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
THIS IS STILL AN ISSUE.
Annoying because the whole reason i use mobx is to keep from having to use STATE.
Using: “computed-async-mobx”: “^3.2.0”, “react-native”: “0.49.5”,
I have the same issue
as mentioned in another solution