1

I want to display a different link in this map function, If x is for example 3 i want to show<Link>Put</Link> otherwise i want to show <Link>Remove</Link>. I am trying to do some conditional but i get errors, how can i write it down?

const mapWorkplace = (arr: SuggestedWorkplace[], deallocation: boolean) =>
  arr.map((x, i) => ({
    ...x,
    action: <Link>Put</Link> || <Link>Remove</Link> ,
    __props: {
      style: { background: !(i % 2) ? "#fff" : "rgba(233, 249, 249, .6)" }
    }
  }));

1 Answer 1

1

Assuming your error comes from the value of action, you can do it using a conditional operator:

const mapWorkplace = (arr: SuggestedWorkplace[], deallocation: boolean) =>
  arr.map((x, i) => ({
    ...x,
    action: x === 3 ? <Link>Put</Link> : <Link>Remove</Link> ,
    __props: {
      style: { background: !(i % 2) ? "#fff" : "rgba(233, 249, 249, .6)" }
    },
}));
Sign up to request clarification or add additional context in comments.

1 Comment

Since Error is not mentioned in Question, it is better to point out that we need to import React from 'react'; too

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.