7

I am new to web development, so this is probably pretty fundamental. I want to add a data attribute to the div tag if the datainfo prop variable is not empty

<div style={{height: props.height - handleHeight()}} data={datainfo ? datainfo : ""}>

But right now the data attribute is added with an empty value if the datavalue is empty. Instead I want it to not appear in the div tag at all.

Can I add the whole thing in the JSX clause or how to do it?

0

1 Answer 1

3

According to this other answer, you should put false instead of "".

<div style={{height: props.height - handleHeight()}} data={datainfo ? datainfo : false}>
Sign up to request clarification or add additional context in comments.

2 Comments

You should add that null and undefined are acceptable values as well. Personally, I'd rather use null here, rather than false. But that's just my preference.
Thanks. data={datainfo} seems to work. But data={datainfo ? datainfo : false} does not. It results in data=false

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.