score:2
Accepted answer
you're creating a sealed object literal with const house = { open: 0 };
check sealed object types from the flow documentation.
try
let house = { };
house.open = 0;
if ( props.door ) {
house.close = 0;
}
or... you can use object.assign
and keep it as a sealed object
const house = object.assign({},
{open: 0},
props.door ? {close: 0} : null
);
note: flow will not allow you to use
const house = object.assign({},
{open: 0},
props.door && {close: 0}
);
because props.door && {close: 0}
becomes a boolean and flow does not support that
Source: stackoverflow.com
Related Query
- Using nested objects with Flow in React state
- React - using nested objects as state with hooks to fill form data
- React State update a nested array with objects based on the id when iterated
- React state comparison with objects and nested arrays
- Using nested objects in React state
- How to set and access values of nested array objects in React state using useState hook?
- Setting react state with nested objects from JSON fetch call
- Using state in react with TypeScript
- Using Dynamic Var with `Set` State in React Hooks?
- Is there any way to see names of 'fields' in React multiple state with React DevTools when using 'useState' hooks
- React hooks: How do I update state on a nested object with useState()?
- What's the best alternative to update nested React state property with setState()?
- Using state setter as prop with react hooks
- How can I use `setState` with objects nested in an array in React JS?
- Dealing with Nested React Components' State Changes
- How to dynamically create objects in state with react hooks?
- Using react HOC with a form. Passing common JSX and state down using a HOC
- How to update the state of nested json object in react using hooks
- Using React Hooks with more than one Key/Value Pair in State Object
- How to delete objects from react state hook array with a button click
- Cycle through objects in an array by setting state with a button React
- Rendering optimization using nested state in React
- Property does not exist on state - Using React Router Hooks with TypeScript
- Nested object destructuring with computed object property names - react state
- Using nested objects in redux initial state and reducers
- Using Styled Components with nested styles for React Search Bar, trying to place two different SVGs at opposite sides of the search bar
- Problem with state in react hooks while using firebase-firestore
- Best way to reset the nested state with using combine reducer in redux-toolkit
- Hide component onClick using state with React
- How do I change react state using a promise with Formik inside handleSubmit to show/hide a div?
More Query from same tag
- Installing React js giving a error. name not provided in package.json
- trying to make clone of spotify app getting error in localhost:3000 TYPEERROR: Cannot read property 'url' of undefined
- How use forwarded ref and internal ref simultaneously in React
- How to clear input field after clicking submit in react js redux
- Adding colDefs dynamically
- Styled Component Semantic kit ( Form . Input )
- What is the difference between yarn build and yarn install?
- Cycling through count in React component
- Webpack 4, babel 7, react, typescript: Unexpected token, expected ","
- React hooks: How to write variables in functional components that in class components were initialized in the constructor
- How to convert float values in JSON to two decimal place using Javascript
- How can delete the div card with its content in react?
- Efficient way to create a Date object in react js
- How can I limit and insert conditions on results returned from API fetch request after using map
- React Redux - state undefined on first render
- Nested function in styled-components
- ReactJS, image is not uploading while it does with Postman
- How to create a full background image
- Pass function as prop
- Module not found: Error: Can't resolve '@mui/icons-material/SearchOutlined'
- How to get type of rootReducer?
- How to create a canvas dynamically in reactjs and add refs dynamically?
- Inline if-else with big chunks of code in JSX
- Scroll to top when using pagination in React
- React hooks using an existing function inState
- React control the order of text inputs in a form
- what it gets called method overriding? or duplicating?
- State is updated in console but not added to screen
- How to know deep inside component hierarchy we have a special component, efficiently?
- Setting up react with express server