score:3
When using a single pair of braces, you basically tell JSX you're going to embed a JS expression. When you have a second pair within the first, you're creating an inlined object literal(as you're already in JS context). When you specify styles through the style
property in JSX you have to supply an object, hence the double braces.
{{...spanStyle}}
Just creates a new object literal and takes all the properties from spanStyle
using the spread operator (...
) so as you noticed already you will get absolutely the same result as simply doing {spanstyle}
but with the overhead of creating an object clone.
score:1
What you are looking for is the spread operator:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
With this syntax you can create a new object, and add some prop overriding any original object prop.
Example:
const spanStyle = {width: '100%', height: '400px'};
<div style={{...spanStyle, height: 'auto'}}>
If you dont need override anything, just skip spread!
score:2
First encasing brackets is for the JSX specification for javascript evaluated portions:
<div style={ Javascripty stuff in here }
So, first brackets starts up javascript mode essentially.
Next set of brackets is in javascript land, which in javascript {}
means new empty Object
Last piece of the puzzle is the spread operator ...
.
When you use the spread operator on an object within the declaration of another object, it sucks all the properties out of that object and applies it to the new object you are calling:
<div style={{...anotherObject}} />
So, if you remember the first brackets activates javascript stuff, it all starts making more sense.
Source: stackoverflow.com
Related Query
- React - difference between double curly brackets vs one curly bracket to enumerate properties
- What is the difference between React functional component <Message id> and js function formatMessage() and which one is better to use?
- What is the difference between React Native and React?
- What is the difference between using constructor vs getInitialState in React / React Native?
- What's the difference between "super()" and "super(props)" in React when using es6 classes?
- React : difference between <Route exact path="/" /> and <Route path="/" />
- Difference between component and container in react redux
- Difference between React Component and React Element
- What's the difference between hydrate() and render() in React 16?
- What is the difference between NextJs and Create React App
- react router difference between component and render
- What is difference between React vs React Fiber?
- Difference between import React and import { Component } syntax
- What is the difference between hashHistory and browserHistory in react router?
- What is the difference between import * as react from 'react' vs import react from 'react'
- React Navigation V2: Difference between navigation.push and navigation.navigate
- What is the difference between using constructor vs state = {} to declare state in react component?
- React Native - What is the difference between StyleSheet.absoluteFill() and StyleSheet.absoluteFillObject()?
- difference between React router.push and router.replace?
- What is the main difference between React Query and Redux?
- What's the Difference between the React Router v4 Router Types?
- What's the difference between a JavaScript function and a React hook?
- React - What is the difference between renderToString and renderToStaticMarkup
- Difference between with and without useEffect in react functional component
- What's the difference between importing React's Fragment from React and React, { Fragment }?
- React Hooks: What is the difference between 'useMutationEffect' and 'useLayoutEffect'?
- What is the difference between React component instance property and state property?
- What is the difference between React component and React component instance?
- React Native - Difference between onChangeText and onSubmitEditing?
- How does React router works and what is the difference between <link> and<Route>
More Query from same tag
- How to render my Modal window and all the information contained inside ( in React)?
- Is `useLayoutEffect` preferable to `useEffect` when reading layout?
- Connecting to multiple collections in MongoDB
- Condition based routing in react
- Replace subsring by an HTML tag in react
- How to develop and test Firebase Callable functions with ReactJS app?
- React ignoring Path causing wrong menu to show
- form with default values in React.FC
- Unit test with redux-mock-store - How can I make this unit test pass?
- redux-form -- Set Value for a field via code?
- Cant set three items on a single row
- $_FILES is empty when sending a POST request using axios in ReactJs
- React-DatePicker updating state with previously selected date
- How can I easily align an input with fluid attribute along with Icon in a grid.column?
- How to stop the previous component from rendering when it is redirected to another component in react
- How dispatch function with Redux-thunk
- Why does resource.data in Firestore rules work incorrectly?
- Create React App adding CORS header
- React How do I make the page allows scrolled down?
- Debounce function call, and clear trailing ones
- Toggle multiple buttons individually inside a react table
- React js. Array elements show more show less with useHooks useState
- React preserve state in custom hook
- React context between unrelated components
- Nav not collapsing when a NavItem is selected on mobile devices
- Antd Modal, clicking on Mask to not do anything
- React with multi element conditionals
- How do I make my ReactJs app display A different message when In different screens?
- How to put paragraph into svg background
- Reuse component used in different context in react