EPUB} 9 10 ); 11 } Notice that in the code above, I’m importing named exports of box , background , bg1 , and bg2 from the file named allStyles.js . Here is the contents of that file: 1 export const box = { 2 margin : "50px" , 3 border : "1px solid gray" , 4 padding : "20px" , 5 borderRadius : "10px" 6 }; 7 8 export const bg1 = { 9 background : "whitesmoke" 10 }; 11 12 export const bg2 = { 13 background : "yellow" 14 }; 15 16 export const fs16 = { 17 fontSize : "16px" 18 }; 19 20 export const fs32 = { 21 fontSize : "32px" 22 }; 23 24 export const fs48 = { 25 fontSize : "48px" 26 }; Let’s inspect the wrapping div of the ComposableStyles component: 1 The way that this works is, after I’ve imported the individual named exports of box , background , bg1 , and bg2 , I’m then using them to compose these four objects into an individual object literal. Notice that the background , bg1 , and bg2 are all style objects that only define the background property style. Since the rest operator works by virtue of overriding previous values, and since all three listed style objects are targeting the background property, the end result is that the value of bg2 is overriding everything before it, and thus, the Pineapple card that gets rendered has a yellow background, because that’s the value that’s set by the bg2 style object. Composability is an important topic in React, and here I’m just scratching the surface. You’
Rate this eBook
| File Name: | ba4a159ead17a15fce82b0eca23ffc77.epub |
| Original Title: | React from Scratch |
| Creator / Author: | Ajdin Imsirovic |
| Language: | English (en) |
| Identifier: | ASIN:255048 |
| Publisher: | Ajdin Imsirovic Publishing |
| Category: | Non-fiction |
| Format: | 📗 EPUB eBook |
| File Size: | 3.5 MB |




