code
I want the "elem" parameter of my component to be another component based on the boolean that is passed into my arrow function.
I have tried passing in "mobile" as a parameter into these arrow functions as it was a parameter of my <Homebar> hook. I’m not exactly sure how local variables work in JSX. Should I instead pass in "mobile=mobile" to set the value as a default param value? Should I just hard code an if else statement before my return? Or are arrow functions not possible within return statements?
2
Answers
ReactJS
at the base level usesJavaScript
itself, so you can pass in parameters the same way as JavaScript callbacks and functions.Example:
For passing parameter with default value, you can pass it as
(param = true)
Although, this is available in the documentation itself. You should refer that first in order to understand React and JS:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions
Your
elem
properties don’t appear to accept a function so it looks to me like you just want some conditional renderingFYI Boolean props should not be set with
={true}
. You can simplify yourHomebar
component using the following