0

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.

1 Answer 1

1

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

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

      ) : (

        <Component2 />
      )}

  </div>
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.