Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

how to fix Objects are not valid as a React child object promise

$
0
0

I create an eLearning app using react and want to split routes to many users (pupils, teachers, and admins) so I use this method

NewRoute.js

const NewRoute = ({
    component: Component,
    type: type,
    ...rest
}) => (
    <Route
        {...rest}
        render={ async props => {
            console.log(await CT.checkType(type));
            return CT.checkType(type) === false ? (
                <Redirect to='/login' />
            ) : (
                <Component {...props} />
            )
        }
        }
    />
);

checkType.js

export default {
  checkType: async (type) => {
    try{
      const res = await axios.get('/api/check/');
      console.log('api response',res);
      return true
    } catch(err) {
      console.error(err.message);
      return false
    }
  }
}

Uncaught Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>