Kirill Stas Kirill Stas - 3 months ago 39
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.



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 = {
        // ...