Adding flair to a object's value in React JS

In my React JS file, I have a map function that I am using to populate a select dropdown with options.

 const options = response.map(k => ({
          value: k.id,
          label: k.description ? `${k.name} - ${k.description}` : k.name,
        }));

I am looking for a way to style the ${k.name} value, such as making it bold and increasing the font size. How can I achieve this by either adding a div or applying inline styles?

Expected Output :

Thank you in advance

Answer №1

Assuming you have a pre-existing Option component, it should be possible to develop a new component that can receive the items from the provided response as properties


const Options: React.FC<Data> = ({ id, name, description }) => (
  <Option value={id}>
    <span className="yourClassHere">{name}</span>
    {description && (
      <span>- {description}</span>
    )}
  </Option>
)

const options = response.map(option => <Options {...option} />);

TS Playground

MUI exmaple

Answer №2

let selection = feedback.map(item => ({
          key: item.id,
          text: item.info ? `${<span style={{fontStyle: "italic"}}>item.type</span>} - ${item.info}` : item.type,
        }));

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

Issues with jwplayer functionality

After downloading the necessary files and carefully following all instructions, I am still experiencing issues with the player not functioning as expected. <code> <html> <head> <script type="text/javascript" src="/jwpl ...

Angular Material Flex is not providing the correct size

There seems to be a problem with certain values for setting the flex property in the Angular Material layout library. The issue is clearly demonstrated in this straightforward example. By clicking through, you can observe that some values display correctl ...

Ways to prevent an array from being reset

My issue involves the clothes and orders tables, along with an array based on Clothes and Orders models. Whenever I add a clothes element into the Orders array and specifically update the amount and price of the selected item, it also updates the Clothes a ...

Unable to upload images on Phonegap ios using formdata

I am facing an issue with image upload in my Phonegap application for iOS. The image upload is not working at times and I am unsure of the exact reason behind this. I am using FormData to upload the image as shown below: <input id="uploadImage" type="f ...

Position two div elements and an hr tag to create a step progress bar

Check out my progress bar design https://i.sstatic.net/u9SRM.png How can I center the 'created' and 'assigned' divs below the circle while ensuring the 'hr' line touches the circle, and it is responsive across different scre ...

When using Vue2, pushing a string to an array simply replaces the existing string instead of appending it

My current task involves manipulating a local data array by adding and removing strings within a method. However, I have noticed that my logic always results in the array containing only a single string passed to the updateIdArr method. Even after removin ...

Repeated actions using jQuery

Being new to jQuery, I am currently exploring ways to repeat functions without the need to continuously write them over and over again. In the code snippet below, you can see that when a button is clicked, it changes to 'I was clicked' in an h1 t ...

Having trouble activating the Tailwind CSS or Intellisense features

I'm having trouble getting my React app to properly style divs using Tailwind CSS. The intellisense feature doesn't suggest any styling options for me either. import './App.css'; function App() { return ( <div className="t ...

Struggling to get the hang of CSS animation?

Here is a code snippet that I am using: //Code for animating skills on view document.addEventListener("DOMContentLoaded", function(event) { function callback(observations, observer) { observations.forEach(observation => { if (observati ...

Customize your Loopback 4 OpenAPI with NSWAG by making filters optional and specifying data types

I am encountering an issue with the Loopback 4 filter on the generated endpoints being marked as required in my Nswag typescript file. I need it to be optional, but I am struggling to locate where this requirement is originating from. The endpoint from my ...

In Django, I am assigning the URL as the category but encountering an error that is expecting a semicolon in JavaScript

I am currently trying to set the category as the URL in Django but I am running into an error that states '; expected.javascript' {% for category in all_categories %} <div onclick="location.href='{% url 'category' categ ...

What is the best way to handle mapping an array with uncertain levels of nesting?

My task involves rendering an array of comments in ReactJs, each of which can have nested comments at unknown levels. I am struggling to figure out how to display these comments with their respective nesting levels. comment 1 -- comment 2 -- comment 3 --- ...

Utilizing React-virtualized: maximizing minWidth exclusively

Can anyone help me figure out how to make the last column width equal to all available space in a block? I've tried setting minWidth, but it's not quite working... Whenever I set a large width for the last column, my other columns on smaller scr ...

What sets apart posting data through an HTML form submission from posting data through an Ajax request?

Recently, I've encountered an issue with my Post API. When calling it through AJAX, the user parameter is received but the StreamReader returns empty. [HttpPost] [Route("getUserBankList")] public IHttpActionResult getUserBankList(UserProfile ...

Perform a function dynamically once a specific textfield is filled and continuously while filling another textfield

Imagine we have two text fields - one for a first name and one for a surname. As I type in the surname field after already filling out the first name, a function called sug() should provide suggestions or perform some action each time I add another letter ...

Creating a modal dialog using a function in a TypeScript file

Hey there, fellow developers! I have a question that might seem simple. So, in my HTML code I've got a Modal Dialog that pops up using ng2 Bootstrap. It's working fine, but... I want to replace this line of code "<button class="btn btn-prim ...

Analyzing JavaScript code coverage through unit testing with Jenkins and SonarQube

We have successfully implemented Jenkins/SonarQube to enforce a requirement that any new code committed by developers must have at least 70% unit test code coverage for Java. However, when it comes to applying the same rule for JavaScript, we encountered s ...

Struggling to dynamically fill the table with Ajax Json data

After retrieving data from my webservice call, I am sending this JSON response: [ [ { "id": 123, "vendorName": "PoppyCounter", "item": "Chocolate" }, { "id": 1234, "ve ...

Looking to showcase website HTML code by simply clicking on a banner image?

I am looking to implement a feature where banner HTML code is displayed in a popup on website when the banner is clicked. For instance, an example of a banner could be: <img src="https://myweb.com/images/banners/1.gif"> Upon clicking the banner im ...

Utilizing a Web API to enhance a progress bar

[I want to mention that I am new to ReactJS] I have a web API that is used for creating employee data. The API takes an array of employee data as input. http://localhost:5000/api/services/app/Employee/AddEmployees The input JSON format is as follows, [ ...