question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using .get() inside a React @observer render function throws an error

See original GitHub issue

Hi @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:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
atljosephcommented, Dec 11, 2017

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”,

0reactions
Ahmed-osamacommented, Nov 30, 2020

I have the same issue

 "computed-async-mobx": "^4.1.1",
    "mobx": "^5.13.0",
    "mobx-utils": "^5.4.1"

as mentioned in another solution

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found