Kirill Stas Kirill Stas - 3 years ago 248
React JSX Question

React: Execute some check before render

Are there the ways how implement this idea:

I wanna do some check before render. If check is true than render. But if check is false, than firstly i need to do

, and only after render.


Answer Source

I think componentWillMount() is literally what you are after but putting it in the constructor() might be a better place for it.

class MyComponent extends React.Component {
  constructor(props) {
    if (theCheck() === false) {
      this.state = {
        // ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download