Material UI allows for the creation of numbered lists with ease. This

<List>
                        {instructionList.map((el) => (
                            <ListItem divider key={el.id}>
                                {el.type === 'number' ? 
                                    <React.Fragment>
                                        <Typography variant="inherit" component="span">
                                            {el.number}
                                        </Typography>
                                        <ListItemText>{el.instruction}</ListItemText>
                                    </React.Fragment> : 
                                    <React.Fragment>
                                        <Checkbox disableRipple />
                                        <ListItemText>{el.instruction}</ListItemText>
                                    </React.Fragment>}
                                <ListItemSecondaryAction>
                                    <IconButton onClick={() => deleteInstruction(el.id)}>
                                        <DeleteIcon />
                                    </IconButton>
                                </ListItemSecondaryAction>
                            </ListItem>
                        ))
                        }
                    </List>

https://i.stack.imgur.com/7bLxa.png

I am looking to conditionally render a numbered bullet point list item or a checkbox based on the value of el.type ('number' or 'checkbox'). How can I achieve this?

Answer №1

Prior to performing the mapping process, you have the ability to apply a filter to the instructionList.

instructionList.filter(item =>
  item.category == 'desired_category'
).map(item =>
  ...
)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

`Node.js troubleshooting: Dealing with file path problems`

I am currently in the process of deploying a node.js based application to IBM's Bluemix and have made some modifications to one of their provided samples. I have included an additional javascript file that initiates an ajax call to PHP, but unfortunat ...

When a label is clicked, the ng-change event is not triggered on the corresponding radio button

I developed a custom directive that allows you to select a radio button by focusing on its label and pressing the spacebar. However, although the radio button is checked, the ng-change function action() does not get triggered. Below is the HTML code snipp ...

Having difficulty controlling the DOM within an AngularJS template

My website utilizes AngularJS templates, specifically a Single Page Application (SPA). Within one of the templates, I am utilizing a tab control from the AngularUI library named Ui-Tabset. During the rendering process, this control generates a ul element ...

Connecting two fields with a line on click in AngularJS

In the top section, there are 10 fields and in the bottom section, there are another 10 fields. I want to be able to connect two fields with a line when they are clicked (one from the top section and one from the bottom section). This connection should app ...

Utilizing d3.csv to load CSV data into an nvd3 multiBar Chart demonstration (in JSON format)

I am attempting to recreate a nvd3.js multiBar Chart using my own .csv data. While I have come across similar questions in the past, none of them have provided a solution specific to my current issue. Some suggestions involve utilizing d3.entries, d3.nest, ...

JavaScript event manually triggered not propagating within an element contained in an iFrame context

I am currently developing a WYSIWYG designer that enables users to choose colors through [input type="color"] fields. The interface includes inputs on the left side and an iFrame on the right side displaying the generated preview. Normally, when ...

Organize Dates in React Table

I need help with sorting the Date column in my code. Currently, the sorting is being done alphabetically. Here is the JSON data and code snippet: JSON [ { "date": "Jun-2022" }, { "date": "Jul-2022" } ...

Leverage Redis to facilitate memory sharing among node.js instances in RxJS

We are currently developing a project that involves creating an event processor using RxJS. The system relies on specific rules where input is collected from various sources and output is generated based on the frequency of inputs exceeding a certain thres ...

The React application is persistently sending a stream of HTTP requests

Currently, I have a web page that retrieves and displays data from a MongoDb using an API. Users can make modifications to the data on this page, causing it to refresh with the updated information. However, upon inspecting the network requests, I noticed t ...

Responsive design is achieved through the use of CSS media queries targeting the

Could someone please clarify the meaning of the following value? Does it indicate that the output device must support exactly 256 colors, or is it acceptable for the output device to have 256 colors or fewer, or does the device need to support 256 colors ...

Having trouble transmitting data with axios between React frontend and Node.js backend

My current challenge involves using axios to communicate with the back-end. The code structure seems to be causing an issue because when I attempt to access req.body in the back-end, it returns undefined. Here is a snippet of my front-end code: const respo ...

Mobile version shows white spaces when using particles.js and bootstrap 4.6

This is how I implement particles.js: <div id="particles-js"></div> @RenderSection("Header", required: false) <main role="main" class="container"> @RenderBody() </main> <script> ...

Ways to return success state to component without the need to modify the store

I am currently working on a simple form in react-redux with the goal of adding a user to the database and displaying a success message upon successful registration. However, I am unsure of the most effective approach to achieve this. Here is what I have so ...

Typescript Redux Thunk

I've been attempting to create a thunk that filters an array and adds the filtered data to a new array, but I keep encountering an error when trying to dispatch in useEffect. The error message reads: "Argument of type '(dispatch: ThunkDispatch&l ...

403 Forbidden - CSRF Token Not Recognized

I am encountering an issue with Node Express and CSurf - 403 (Forbidden) Invalid csrf token. After reviewing other solutions and attempting all available options, I am still unable to resolve this. The API functions perfectly when tested in Postman. Howe ...

Tips on utilizing setInterval in a Vue component

When defining the timer in each individual my-progress, I use it to update the value of view. However, the console shows that the value of the constant changes while the value of the view remains unchanged. How can I modify the timer to successfully change ...

Challenge encountered when rendering markdown in NextJS/React

Having trouble rendering markdown in NextJS/React again. Here's the code I'm using: import ReactMarkdown from "react-markdown"; import gfm from 'remark-gfm'; const PostContent = () => { const source = ` # Hello, ...

Design a button for removing the selected value in select2

Can anyone provide some guidance on using select2? I am working with 2 select2 elements, and I want the selected value to be displayed on a button instead of in the input area of the select2. This way, the select2 will still display the placeholder text. ...

Having trouble with obtaining precise mouseup and mousedown coordinates

Currently, I am working with react and typescript for my project. I have implemented a canvas element where I am attempting to draw a rectangle based on mouseup and mousedown events. However, the issue I am facing is that the rectangles are being drawn in ...

Clicking on Rows in DataTables: Enhancing

I have been utilizing the jquery datatables plugin, and have encountered an issue with the row click functionality. Strangely, it only seems to work on the first page of the table. When I navigate to any subsequent pages, the row click fails to respond whe ...