BobN1971
BobN1971

Reputation: 1

Conditional rendering react js

Ok, trying to render date from one component into a second component, but using conditional rendering so if date on component 1 is null, component 2 date field will not render. New to react. using following logic.

const enpDate = (earlyNotificationDate);
if (enpDate) {
    moment(earlyNotificationDate, 'MM/DD/YYYY')
}

Mentor does not like it and would rather wrap in function. Cannot get function to render properly.

Upvotes: 0

Views: 158

Answers (1)

G.Mestanza
G.Mestanza

Reputation: 41

You can use a ternary function condition ? value_if_true : value_if_false like so

const component = ({ isNull}) => (
  <div>
    {isNull ? 
      (
        <Component1 />

      ) : (

        <Component2 />
      )}

  </div>
)

Upvotes: 1

Related Questions