score:2
Accepted answer
const Number = ({ number }) => {
let segments = [];
switch (number) {
case "1":
segments = ["b", "c"];
break;
case "2":
segments = ["a", "b", "d", "e", "g"];
break;
case "3":
segments = ["a", "b", "c", "d", "g"];
break;
case "4":
segments = ["b", "c", "f", "g"];
break;
case "5":
segments = ["a", "c", "d", "f", "g"];
break;
case "6":
segments = ["a", "c", "d", "f", "e", "g"];
break;
case "7":
segments = ["a", "b", "c"];
break;
case "8":
segments = ["a", "b", "c", "d", "e", "f", "g"];
break;
case "9":
segments = ["a", "b", "c", "d", "f", "g"];
break;
case "0":
segments = ["a", "b", "c", "d", "e", "f"];
break;
default:
segments = ["a", "b", "c", "d", "e", "f"];
}
return (
<div className="container">
{segments.map((segment) => (
<div key={segment} className={`segment segment-${segment}`}></div>
))}
</div>
);
};
export default Number;
score:2
const Numbers = ({ singleNumber }) => {
const switchDisabled = (element) => {
const allSegments = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
let disabledSegments = [];
switch (element) {
case 2:
disabledSegments.push("c");
disabledSegments.push("f");
break;
case 6:
disabledSegments.push("b");
break;
default:
break;
}
};
return (
<div className="container">
{allSegments.forEach(segmentLetter => {
const disabledClass = disabledSegments.includes(segmentLetter) ? 'segment-disabled' : '';
return (
<div className={`segment segment-${segmentLetter} ${disabledClass}`} />
)
})}
</div>
);
};
Source: stackoverflow.com
Related Query
- Map array to return components with different classNames
- React: Map multidimensional array with different keys
- React - Map Over Array Of Components To Return
- Cannot access array inside of map function to return props to different component
- How to map an array of objects to different components props in React?
- Map over TypeScript array of 2 different types with a condition for a property that only exists on one Type?
- map an array with index keys to return a list of items react JS
- Don't manage to return on different lines objects from an array using map
- How to compare nested array with the map or filter and only return with first match inside?
- How to map an array with different zIndex each element in react.js
- React native mapping through array with object childs - working different as in react web?
- Redux: How to add item to Array, and return Array with all items added
- ES6 array map doesn't return anything: ReactJS
- React, async loading for multiple sections/views with different components
- Why does map() return an array with undefined values?
- How do I render components with different layouts/elements using react-router-dom v6
- Styled Components - two different elements with the same styles
- How to handle components with different routes in react js
- How to map an array with unknown nesting levels?
- React / Javascript map function - return array
- React Array Map With Firebase Issue
- Return fields by comparing to array of objects using Map Filter
- How to Bind different react components with the same react-router route depending on redux state?
- Styled Components with Typescript return type is any
- How to access different components by routes with slug only in react-router-dom?
- How to use if statement in array map function with next.js
- Es6 map array with html doesn't work in JSX?
- Map an array of arrays with ReactJS
- Jest jest.mock function with different return value
- React useState to return a fake image with two different conditions
More Query from same tag
- react add data from MongoDB to email
- ReactJS: Save input value on blur and not on every key stroke
- ReactJS- Pass the JWT token as Authorization in axios method for http request
- Type 'StaticImageData' is not assignable to type 'string'
- Reactjs: How to select one or multiple cards when clicked with a state hook?
- React doesn't get custom attribute with the e.target.getAttribute() method
- How to style input tag without class with JSS
- Tailwindcss use hover over group-hover is not working
- Javascript (React.js) - Refactor a switch-case
- Update Boolean Within UseState Hook
- Options for token storage and refresh in SPAs
- Why is my state variables being rendered twice in reactjs
- How to get global.window.localStorage inside getServerSideProps
- Add elements in modal window
- React TinyMCE editor set bbcode content dynamically
- How can I refresh the data(API) in react js?
- How To Test functions passed as props in React, Jest, Enzyme
- Why is this unary function within another javascript function?
- React Routing with Express, Webpack dev middleware, React router dom
- React 'Set is undefined', on Sharepoint
- react router - don't match multiple paths (v4)
- TypeError: Cannot read properties of null (reading 'push') react.js
- React this.props.children.apply is not a function
- not able to use $pull (Mongoose) to remove an object in an array for a user model
- Cannot find module 'webpack/lib/rules/BasicEffectRulePlugin'
- React: Overwrite an array with another array. Error: Uncaught TypeError: ...is not a function
- How to add options to react-perfect-scrollbar in react
- Too many re-renders, trying to change an svg in React, how to fix this
- Get another component input value React js
- Can I set value of an object by accessing other values in this object?