score:0
you can do that using ternary operators
render() {
return (
<div>
{this.state.properties.somemoredata ?
// somemoredata exists
(<div>some jsx stuff</div>)
:
//somemoredata does not exist
(<div>some other jsx stuff</div>)
}
</div>
)
}
score:2
typically, you just do something like:
render() {
return (
<div>
{
this.state.properties.somemoredata && (
<div>some other jsx stuff</div>
)
}
</div>
)
}
however, cannot use 'in' operator to search for 'somemoredata' in undefined
seems to indicate that for whatever reason this.state.properties
is undefined
. not sure why with only the code you've posted, but i would look at that.
Source: stackoverflow.com
Related Query
- Conditional rendering based on state
- Conditional rendering in React based on state
- Conditional rendering in React based on current component state
- conditional rendering of components based on state change
- Rendered fewer hooks than expected. This may be caused by an accidental early return statement. Conditional rendering component based on state
- Rendering different components based on hook state using conditional rendering returning null
- State machines and UI: Rendering based on 'node-level' states instead of 'leaf' states
- Gatsby: React conditional rendering based on window.innerWidth misbehaving
- Conditional Rendering in React won't work, state not working properly?
- Conditional rendering based on user input
- testing conditional rendering that relies on state using react testing library
- Test conditional rendering of components based on ContextAPI data using Jest and Enzyme
- React conditional render based on state
- Trying to conditional render react-fontawesome icon based on current state
- wrote a React code snippet to implement conditional rendering and am not able to update the state of {Left} and {Right}
- React: dynamic rendering of a component based on state
- React conditional rendering not recognising true from state
- State updates are unclear and not rendering my catalog of products based on menu selection
- Conditional Rendering in Styled Component based on Parents' Props
- React state setting timing for conditional rendering
- React: Conditional rendering of functional components using state | is not a function error
- how to trigger conditional rendering when a state value is changes right now conditional rendering is working only when application is loaded
- Rendering different navbars based on state
- Animate conditional rendering based on props with react-spring
- Conditional rendering of JSX based on JSON value not matching
- How can conditional rendering based on privilege
- Conditional rendering parts of form based on selected option
- Can i use multiple state value inside conditional rendering - ReactJs
- Conditional Rendering based on async function
- Javascript How to give color using conditional statement based on json array state value
More Query from same tag
- I wish to toggle on and off the display of my <p> tag
- React-Redux, LocalStorage: TypeScript error while saving data lcoally
- How to upload image file using ReactJS to api using NestJS with bytea datatype
- Reactjs react-google-maps undefined
- React window is not closing when the user clicks the button
- In React Native, How Can I Use KeyboardAvoidingView with a Modal in iOS?
- How to get rid of Typescript type error when overriding MuiContainer classes?
- React won't render within map function
- Components are not rendering while using .map() on array of objects in React
- 'ResizeObserver' only refers to a type, but is being used as a value here
- React router only works with / path
- How to passing data between pages Reactjs with Hooks?
- How do you destructure a React useState hook into a namespace?
- Fill Dropdown with Fetched API Items
- How do I render a prop which is actually a component?
- Navigation with Material-UI Icons
- React js with browserify and bootstrap raising error
- FirebaseError: Function Query.where() requires a valid third argument, but it was undefined
- How to pass an Array from Child component to Parent Component in react
- How to convert unsafe_componentwillreceiveprops(nextprops) to useEffect
- Rendering empty space in React
- how do i open a specific collapse accordian when using a anchor component in react typescript
- Cleaner way to update object in array
- Draft.js (react-draft-wysiwyg): text update from the outside of the Editor component does not work
- recharts img not rendering in customized dot
- How can I mock useAxios hook from axios-hooks using Jest? (Error: Uncaught [TypeError: undefined is not a function])
- How an I access data in map to set properties?
- Making a value of an object to null in a object list in javascript
- "sudo npm install -g create-react-app" command not working
- HTML isn't rendered before after translate3d transition