How can I add unique keys to React/MUI Autocomplete component?

You can define your own renderOption that can return the list item with a correct key value. Your code complains about the duplicated keys because by default, Autocomplete uses the getOptionLabel(option) to retrieve the key: <Autocomplete renderOption={(props, option) => { return ( <li {…props} key={option.id}> {option.name} </li> ); }} renderInput={(params) => <TextField {…params} label=”Movie” />} … Read more

Media query syntax for Reactjs

You can make media queries inside React: import React, { Component } from ‘react’; class App extends Component { constructor(props) { super(props) this.state = { matches: window.matchMedia(“(min-width: 768px)”).matches }; } componentDidMount() { const handler = e => this.setState({matches: e.matches}); window.matchMedia(“(min-width: 768px)”).addEventListener(‘change’, handler); } render() { return ( <div > {this.state.matches && (<h1>Big Screen</h1>)} {!this.state.matches && … Read more

Set loading state before and after an action in a React class component

you can wrap the setState in a Promise and use async/await as below setStateAsync(state) { return new Promise((resolve) => { this.setState(state, resolve) }); } async handleChange(input) { await this.setStateAsync({ load: true }); this.props.actions.getItemsFromThirtParty(input); await this.setStateAsync({ load: false }) } Source: ASYNC AWAIT With REACT

How to have nested loops with map in JSX?

You need to wrap it inside an element. Something like this (I’ve added an extra tr due to the rules of tables elements): render() { return ( <table className=”table”> <tbody> {Object.keys(templates).map(function (template_name) { return ( <tr key={template_name}> <tr> <td> <b>Template: {template_name}</b> </td> </tr> {templates[template_name].items.map(function (item) { return ( <tr key={item.id}> <td>{item}</td> </tr> ); })} </tr> … Read more