Encountering a Console warning while working with the Material UI menu. Seeking advice on how to resolve this issue as I am integrating HTML within a text

Caution: PropType validation failed. The prop text provided to LinkMenuItem is invalid as it should be a string, not an object. Please review the render method of Menu.

Below is the code snippet:

var menuItems = [ // text is not valid text
  { route: 'test1', text: <div className="sideMainNav User"><i><img src="/static/images/icons/test1.svg" alt="test1" /></i><span>test1 </span></div>, type: MenuItem.Types.LINK, payload: '#/test1' },
  { route: 'test2', text: <div className="sideMainNav"><i><img src="/static/images/icons/test2.svg" alt="test2" /></i><span>test2</span></div>, type: MenuItem.Types.LINK, payload: '#/test2' },
  { route: 'test3', text: <div className="sideMainNav"><i><img src="/static/images/icons/test3.svg" alt="test3" /></i><span>test3</span></div>, type: MenuItem.Types.LINK, payload: '#/test3' },
  { route: 'test4', text: <div style={{margin:'0px -8px',fontWeight:'bold',color:'#58595B',fontSize:'14px'}}>test4</div>, type: MenuItem.Types.LINK, payload: '#/test4' },
  { route: 'test5', text: <div style={{margin:'0px -8px',fontWeight:'bold',color:'#58595B',fontSize:'14px'}}>test5</div>, type: MenuItem.Types.LINK, payload: '#/test5' },
  { route: 'test6', text: <div style={{margin:'0px -8px',fontWeight:'bold',color:'#58595B',fontSize:'14px'}}>test6</div>, type: MenuItem.Types.LINK, payload: '#/' },
  { route: 'test7', text: <div className="sideLogout" onClick={this.logout}>test7</div> },
  { route: 'test8', text: <div className="sidenavPlink"> <a href="#/">test8</a></div> },
  { route: 'test9', text: <div className="sidenavHelplink"> <a href="#/"><span>Help</span><i><img src="/static/images/icons/test9.svg" width="16px"/></i></a></div> }
];

Answer №1

According to the Material-UI source code, the text property must be a string...

text: React.PropTypes.string.isRequired,

It is recommended to use the MenuItem component, which allows for nodes in the primaryText property.

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

Utilizing AJAX in Wordpress to Dynamically Update HREF Links

My website now has AJAX functionality, and you can see a live example at www.mathewhood.com. I am interested in changing the URL format when clicked from To something like , without the /sitefiles/ for security reasons. Below is my code. If anyone is ex ...

Unlocking the power of translation in React: Implementing Amazon Translate or Google Translate for AXIOS responses

I'm currently working on converting Axios JSON responses in React. Here is the code snippet: axios.get('https://jsonplaceholder.typicode.com/users') .then(res => { ...translation_logic_here setU ...

Event in Bootstrap modal fails to activate

I've been attempting to link some code to execute when my modal is opened. Despite successfully opening the modal, I am puzzled as to why my event fails to trigger. Below is the structure of my modal: <div id="details" class="modal fade" style="d ...

While JSON Lint may declare the JSON data as valid, JSON.parse may still encounter an error when trying

I'm struggling to parse a simple JSON object. It's strange because when I check the validity of my JSON string on JSONLint (http://jsonlint.com/), it shows that it's valid. var data = '{"token":"9eebcdc435686459c0e0faac854997f3","email ...

Vue table displaying a list of books with a button that allows users to easily send the title of the

Hey everyone, I am new to Vue and struggling with a certain task. I have two tables: Books and Booking. Books: ID, NAME, AUTHOR etc. Booking: ID, ID_USER, ID_BOOK I'm creating a page in Vue that displays all bookings, but the table only shows the BOO ...

Issues with GitHub Pages' HTTP "Post" Request

I am currently in the process of developing my own website hosted on GitHub Pages. This website is being created using react.js and what you see here is a contact form. The issue I am facing is that I am unable to send a POST request to a Google Cloud P ...

formik does not support using the "new Date" function as an initial value

I have been trying to set the initial value of a date in my component like this, but when it renders I am encountering an error. const formik = useFormik ({ initialValues: { dob: new Date () } }) During this process, I'm facing the follow ...

What could be causing the browser.get method to fail to redirect to the specified URL?

I have organized my files in a folder structure that looks like this: project structure Currently, I am following the steps outlined in this particular tutorial The contents of my package.json file are as follows: { "name": "node_cucumber_e2e", "ver ...

Retrieve the value of a field from a Formik form integrated with Material UI

I've been working on a way to disable a checkbox group depending on the selected value of a radio group. I took inspiration from the technique outlined in the final section of the Formik tutorial. Using React context has definitely helped clean up the ...

The chai property "matchSnapshot" is not valid

After following the instructions provided at this link, I am now in the process of writing basic Jest tests for my React application that uses the Create-React-App starter kit. I came across a recommendation mentioned here that advises against installing ...

Transfer responsibilities of events to the canvas and then fetch the Element in the handler

Currently, I am utilizing the Raphaël library to create a network graph, where nodes are depicted as circles. Users have the ability to dynamically add nodes by clicking on the canvas. When a new node is added, an Element object is pushed into both a Set ...

Loop through a non-array or non-object / handling both arrays and non-arrays equally

Sometimes, I find myself needing to handle arrays and single objects in a similar manner. For instance, I may have an object property that can be either an array or just a string (like the scale property): [ { "name": "Experiment type14", "id": ...

Retrieve JSON data within React without the need for importing it

Recently, I've been incorporating data from a JSON file into a React component in a unique way: import data from '../../public/json/data.json'; Using the innovative create-react-app tool, upon running npm run build, the expected behavior o ...

Unexpected data displayed in React list after item deletion issue

I am currently working with a basic list of student objects that include their names and scores in the state. The name is displayed using <b>{student.name}</b>, while the score is displayed using <input type="text" defaultValue={s ...

Tips on saving content that changes automatically

I am curious about the best way to store dynamically displayed HTML content. For example, when a certain element is clicked on a website, I want text to appear elsewhere on the page. One idea I had was to create a variable in a JavaScript/jQuery script to ...

Getting an error message "idpiframe_initialization_failed" while trying to login with Google in a React.js application

I recently integrated Login with Google into my react.js app. I followed the steps outlined in a tutorial video which can be found here: https://youtu.be/75aTZq-qoZk. Even though I registered my app with my client Id on Google Cloud Platform under the "Au ...

Logging in using Selenium WebDriver in Java

I'm just starting out with selenium webdriver and I need to automate a webpage for my project. Right now, I'm working on the login page but I'm having trouble with the login button. I'm not sure which locator to use for it. The login bu ...

Notifying Users of Payment Updates

In the process of developing our application, we integrated a Payment gateway called flutterwave. Every time a payment is successful or fails, a webhook is triggered which prompts us to send notifications through emails, SMS, and update payment statuses in ...

Automatically populate the options of a dropdown menu using jQuery

I am a beginner in the world of Javascript, JSON, and jQuery. I am seeking some guidance as I navigate through this new territory. On my JSP page, there is a drop down list that needs to be populated with content when the page loads. To achieve this, I hav ...

Why is the type of parameter 1 not an 'HTMLFormElement', causing the failure to construct 'FormData'?

When I try to execute the code, I encounter a JavaScript error. My objective is to store the data from the form. Error Message TypeError: Failed to create 'FormData': argument 1 is not an instance of 'HTMLFormElement'. The issue arise ...