0

0

I have state controlled by a dropdown menu, which when you select will setState. Simple.

What I want to do is when there is nothing selected, have a generic 'Select below', but if something is selected, I wanted to set that as the option selected.

For example: if(!selectedStyle THEN 'Choose Below' ELSE selectedStyle)

selectedStyle holds the state selected, how would I write out this component?

{selectedStyle>0: selectedSyle || Choose}

But also this is my component, does anyone see the correct way to write it out?

<Dropdown>
                        <Dropdown_Button
                        onClick={e => 
                            setisActive(!isActive)}
                        >
                            {selectedStyle>0: selectedSyle || Choose}
                            
                            <span>
                                <KeyboardArrowDownIcon/>
                            </span>
                        </Dropdown_Button>
                        {isActive &&
                        <Dropdown_Content>

                            {styleSelection.map((option) => (
                                <Dropdown_Item onClick={(e) => {
                                    setselectedStyle(option)
                                    setisActive(false)
                                }}
                                >
                                    {option}
                                </Dropdown_Item>
                            ))}
                        </Dropdown_Content>
                        }
                
                    </Dropdown>
1
  • Perhaps you're looking for {selectedStyle > 0 ? selectedStyle : "Choose"}? Commented Sep 10, 2022 at 1:21

1 Answer 1

1

You can simplify it to just {selectedStyle || "Choose style"}

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.