score:2
Use template strings
to embed javascript expressions or values between strings. You can do something like this.
ms.map((eachname, index) => (
<div classname="mainblock" key={index}>
<div
classname="insideblock"
style={{ borderRight: `1px solid ${eachname.color}` }}
>
{eachname.Name}
</div>
</div>
));
More information on template string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
score:0
In case, for some reason, you don't want to use template strings you can use:
style={{
borderRightWidth: 1,
borderRightWidth: 'solid',
borderRightColor: eachname.color,
}}
score:0
You can also use styled components if you don't want to use inline styling and make component more reusable and readable. More information Styled components
import styled from 'styled-components'
const StyledDiv = styled.div`
borderRight: ${props => props.color}
`
ms.map((eachname, index) => (
<div classname="mainblock" key={index}>
<StyledDiv color={eachname.color}>
{eachname.Name}
</StyledDiv>
</div>
));
Source: stackoverflow.com
Related Query
- How do I add style inline the color code which I m getting from an array of object
- How to keep and loop the style of HTML element from an Array in REACT?
- How to consecutively add values from one array to another and store the value in a new array in javascript?
- How can I add paging on the antd select ? Because getting data from the interface is huge. So I want to implement paging
- How to get seperate daily array from the weather API array which gives a 5 days every 3 hours report
- How can I get all the object inside an object which is present inside an array and add the result into another array
- So how can I sum all the values in all objects in an array which is coming from react redux?
- Removing specific item from nested array and saving the result, how to make this code cleaner
- How to add multiple Objects to an empty array react after getting response from Api react
- How to select one item in a dropdown which shows the data from an array in react?
- How to map the required data of array of object which i got from api call to usestate variable
- How to add these elements in array to customize the code in reactjs
- setstate object:{array:[]} in reactjs how could i add the **key and value inside the array which is in the state object**?
- How to get separate daily array from the weather API array (For React Redux) which gives a 5 days every 3 hours report
- how to change only the color of the chip clicked in react from a dynamically created array of chips
- How do I style or control the elements that are saved from a list/key of an array in ReactJS?
- How to add objects retrieved from fetch request to the state array in React and then update the view?
- How to remove an item instantly from the UI which is in a useState array
- How can I store the data from scanning a QR code in an array using react?
- How can I loop an array in the inline style in jsx?
- how to add inline style width:calc(100% / var) in reactjs?
- How to Lazy load the background image inside the inline style property (React)?
- How do I add an item to the front of a state array in React
- How to add !important into React inline CSS style
- How to override style of nested Material UI component from the ancestors?
- how to write inline js event handler code in the react component using "this"
- How can I add MUI theme color to inline style?
- How do i iterate over an array of object in react.js and add the values of prices in the object as shown below
- How to add className to list from map array depending on object value
- how spread syntax in the reducer is different from just returning the array coming from the action?
More Query from same tag
- React filter posts firebase
- How can I increment values in map fields?
- Getting the event object with Underscore debounce[React]
- React useEffect return best practice
- Devise Token Auth Will Not Authenticate for PUT Route
- react router not rendering the component when using redux
- Conditional rendering in react js(Condition inside one more condition)
- how correctly use ternary operator in react js?
- I dont understand why this infinite loop wont stop (React useEffect hook)
- React useEffect is returning empty data when page loads for the first time
- System notification for hot module replacement WebPack ZSH
- CORS error on httpsCallable firebase in Create React App
- React State Not Being Overwritten
- React Hooks: Best practise in passing state between children of hook component
- Change colour of nextjs - tailwind component based on prop
- CSS is completely ignored
- Why filtering data in redux store by favourite is not working?
- react native camera roll .heic files
- how to make Redux state reset every time React component starts rendering
- React child components do not render
- I am trying to put a list of countries in a .js file and export it for reuse. Getting errors
- React - deleting array elements stored in state deletes wrong element
- React - this is undefined when binding function to component
- Getting checkbox state in React JS
- PUT request doesn't work on Axios
- Routing with Django and React
- Adding props to constructor as this.prop
- adding value inside an input - React
- Using preventDefault in React.js
- Sending a details request to Google Places API - (CORS error)