Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export in react js based on a condition?

I have two loggers but i am facing a problem. i want something similar to this. HOwever if i use only one logger without the if case then it works fine.

if(process.env.NODE_ENV === 'DEVELOPMENT')
{
    export default logger_dev;
}
if(process.env.NODE_ENV === 'PRODUCTION')
{
    export default logger_prod;
}
like image 889
Aditya Chandrayan Avatar asked Jul 18 '16 07:07

Aditya Chandrayan


People also ask

What is conditional rendering in react JS?

In React, you can create distinct components that encapsulate behavior you need. Then, you can render only some of them, depending on the state of your application. Conditional rendering in React works the same way conditions work in JavaScript.

Can I export a state in React?

There are two ways to do this. The first one is to use something like redux. where you have global store for the state which can be shared across different components. import React, {Component} from 'react'; import './App.

How do you write if condition in JSX?

We can embed any JavaScript expression in JSX by wrapping it in curly braces. But only expressions not statements, means directly we can not put any statement (if-else/switch/for) inside JSX.


1 Answers

const logger = process.env.NODE_ENV === 'PRODUCTION' ? logger_prod : logger_dev;
export default logger;
like image 103
Vitaly Kravtsov Avatar answered Oct 22 '22 03:10

Vitaly Kravtsov