N
N
nen0y2020-10-04 15:00:29
React
nen0y, 2020-10-04 15:00:29

How to make the value of a variable equal to the value from the object?

The name of one of the status states ('published', 'canceled', 'error' ... ) is passed to the component. After that, with the help of material ui, the appearance of the component should change.

border: (props) =>
            props.status === 'published'
                ? "2px solid #F6AD55"
                :  "2px solid #9ae6b4",


Question: what script to write so that it applies the correct style when the class name matches (switch-case, not suitable, because there can be more than 10 statuses and you don’t want to write a separate case for each)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-10-04
@nen0y

const borders = {
  published: "2px solid #F6AD55",
  ...
}

 ...

return borders[props.status]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question