I am currently having an issue rendering a component using multiple ternary operators.
Here is my code:
{data.shippingData ? (
<CheckoutPayment data={data} setData={setData} />
) : data && data.agree === true ? (
console.log("Hello World")
) : (
<CheckoutShipping setData={setData} />
)}
The <CheckoutPayment /> and <CheckoutShipping /> components successfully rendered without issues, the issue lies in having to render another component using this condition data && data.agree === true. In the above code, I tried using console.log to log "Hello World" but to no avail.
Here is how the data model is structured in the <CheckoutPayment />:
{shippingData: {firstName, lastName, streetAddress, state, city, phoneNumber }, agree: true}
I took the data from the <CheckoutPayment /> component into the global state where I have to pass the data to another component.
The data is available in the state. In fact, I console.log the data to confirm if it was there in which it was.
What I have in mind to achieve is:
- If there is
shippingDatain data object I want to render<CheckoutPayment />else if - There is
shippingData and agreein the data object I want toconsole.log("Hello World")else - Render
<CheckoutShipping />
My question is, is there a way I might have misused the ternary operator or I am not getting something right.