0

This is the recipe page component

const RecipePages = (props) => {

return (
    <div>
        < h5 className="page-header" > Steps</h5 >
        <div className="page-content">
            <ol>
                {
                    str1 = props.props[0].steps.split('\n'),
                    str1.map((elem) => {
                        return (
                            <div>
                                <li>{elem}</li>
                            </div>
                        )
                    })

                }
            </ol>
        </div>
    </div >

)
};

This is where I am using ?? operator

{
     (0 < items[0].steps.length < 8) ??
         <div className="demoPage page">
            <RecipePages props={items} initial={0} count={items[0].steps.length}></RecipePages>
          </div>
}

I am getting the following error

Error: React.cloneElement(...): The argument must be a React element, but you passed null.

I am trying to print the recipe in a form of a book so I need to add new pages according to the recipe length, that's why I am using this approach.

2
  • (0 < items[0].steps.length < 8) doesn't do what we all wish it would -- check out: stackoverflow.com/questions/16655959/… Commented Jul 5, 2021 at 19:46
  • still getting the same error although i changed it to 0 < items[0].steps.length && items[0].steps.length < 8 Commented Jul 6, 2021 at 3:14

1 Answer 1

1

(0 < items[0].steps.length < 8) will return true or false and the Nullish coalescing operator will check for null or undefined

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.