My strong recommendation is two-fold:

  • Use the find method to find the correct topic.
  • Don't use state to redundantly store information you already have from props. Storing information you already have can result in divergence. In this case, we can just find the appropriate topic in the render method:
import React, { Component } from "react";

import topics from "./topics.json";

class Tutorial extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    const selectedTopic = topics.find(
      (topic, index) => page.url === this.props.match.params.url
    );

    return (
      <div className="Tutorial">
        <div className="ca-nav-spacer w3-hide-small"></div>
        {selectedTopic.name}
        {this.props.match.params.url}
      </div>
    );
  }
}

export default Tutorial;
Answer from Nick on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_es6_array_map.asp
React ES6 Array map()
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep ... The map() method creates a new array with the results of calling a function for every array element.
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_es6_array_methods.asp
React ES6 Array Methods
One of the most useful in React is the .map() array method. The .map() method allows you to run a function on each item in the array, returning a new array as the result.
๐ŸŒ
LaunchCode
education.launchcode.org โ€บ intro-to-web-dev-curriculum โ€บ react-part-2 โ€บ reading โ€บ mapping โ€บ index.html
The map( ) Function :: Introduction to Web Dev
October 17, 2023 - map() map() is used for iterating through or displaying lists of similar objects of a component in React. The map() function creates a new array, which it renders to the DOM. This allows you to manipulate data from an array without changing the original array.
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_lists.asp
React Lists - React Fundamentals
In React, you will render lists with some type of loop. The JavaScript map() array method is generally the preferred method. If you need a refresher on the map() method, check out the ES6 Array map() section.
๐ŸŒ
Upmostly
upmostly.com โ€บ home โ€บ tutorials โ€บ how to use map() in react applications
How to use map() in React applications - Upmostly
March 11, 2022 - The simplest way to carry out this operation is by using the map function. Weโ€™re calling map on the array users, using the destructuring assignment to reach into each of the user objects and select the name of that particular user. The callback functions returns the name, which gets written into the new array.
Top answer
1 of 1
1

I re-organized your code a bit to work as a functional component. As others were commenting, you need to use state to re-render your components on updates. I removed count since .map allows for indexing.( you can add it back as a variable inside TaskFunction if you deem necessary )

W3 School's example works because they are not updating state. They have a list that is pre-set with values and render those values.

Lastly, your map function need to 'return' the element. As in the w3 school's example, map returns the Car component. So what you had was a little mixed up.

Hope this helps.

function App() {
  const [tasks, setTasks] = React.useState([])
  const generateValue=()=>{
    let someValue = Math.random() *10
    let newValue = {value: someValue}
    setTasks([...tasks, newValue])
  }
  return (
    <div>
      <button onClick={()=>{generateValue()}}>Add New Item</button>
      <h1>List</h1>
      <ul>
        {tasks.map((task, index)=>(<li key={index}>{task.value}</li>))}
      </ul>
    </div>
  )
}

ReactDOM.createRoot(document.querySelector("#app")).render(<App />)
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<div id="app"></div>

In a comment you ask to see the state example using the old style class components -

class App extends React.Component {
  state = {
    tasks: []
  }
  generateValue = () => {
    let someValue = Math.random() *10
    let newValue = {value: someValue}  
    this.setState({ tasks: [ ...this.state.tasks, newValue ] })
  }
  render() {
    return (
      <div>
        <button onClick={this.generateValue}>Add New Item</button>
        <h1>List</h1>
        <ul>
          {this.state.tasks.map((task, index)=>(<li key={index}>{task.value}</li>))}
        </ul>
      </div>
    )
  }
}

ReactDOM.createRoot(document.querySelector("#app")).render(<App />)
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<div id="app"></div>

Without public class fields -

class App extends React.Component {
  constructor() {
    super()
    this.state = {
      tasks: []
    }
  }
  generateValue() {
    let someValue = Math.random() *10
    let newValue = {value: someValue}  
    this.setState({ tasks: [ ...this.state.tasks, newValue ] })
  }
  render() {
    return (
      <div>
        <button onClick={this.generateValue.bind(this)}>Add New Item</button>
        <h1>List</h1>
        <ul>
          {this.state.tasks.map((task, index)=>(<li key={index}>{task.value}</li>))}
        </ul>
      </div>
    )
  }
}

ReactDOM.createRoot(document.querySelector("#app")).render(<App />)
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<div id="app"></div>

๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ blogs โ€บ map-method-in-react-js
Map Method In React JS
April 28, 2022 - The map() method creates a new array by calling a provided function on every element in the calling array. Add a new file in src folder and named it as Mapdemo.js as below. import React,{Component } from 'react' function MapDemo(){ const array1 ...
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @hammadrao891 โ€บ understanding-the-map-function-in-react-a-comprehensive-guide-887cee7f7955
Understanding the Map Function in React: A Comprehensive Guide | by Hammad Rao | Medium
December 14, 2023 - The `map` function is a fundamental tool in React development, offering an efficient way to render dynamic lists. Understanding its usage and adhering to best practices, such as providing unique keys and maintaining immutability, are key to ...
๐ŸŒ
CodeChef
codechef.com โ€บ learn โ€บ course โ€บ react-js โ€บ CREACT026 โ€บ problems โ€บ PREACT0121
Map() Method in Javascript in React JS for Front-end development
let numbers = [5, 10, 15]; let divided = numbers.map(num => num / 5); console.log(divided); // Output - [1, 2, 3] In this example, we're dividing each number by 5. Since the arrow function is a single line without curly braces, it automatically returns the result.
๐ŸŒ
React
legacy.reactjs.org โ€บ docs โ€บ lists-and-keys.html
Lists and Keys โ€“ React
function NumberList(props) { const numbers = props.numbers; const listItems = numbers.map((number) => <li>{number}</li> ); return ( <ul>{listItems}</ul> ); } const numbers = [1, 2, 3, 4, 5]; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<NumberList numbers={numbers} />);
๐ŸŒ
Keyhole Software
keyholesoftware.com โ€บ home โ€บ reactโ€™s unique looping tool for beginners
React's Map Function for Beginners | Keyhole Software
June 23, 2025 - While traditional looping techniques such as while loops or for loops are still usable in React, developers have a unique tool at their disposal for looping through a wide variety of arrays and key-value pairs. This React tool is known as the map() function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-use-map-to-create-lists-in-reactjs
How to use map() to Create Lists in ReactJS ? | GeeksforGeeks
October 10, 2024 - The map function is generally used to render the list items dynamically in react. This function iterates over the array and each iteration returns the JSX for respective item.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ home โ€บ technologies โ€บ react โ€บ map() function in react
Map() Function in React
December 22, 2023 - At its core, the map() function is a fundamental JavaScript method used to create a new array based on an existing one. It iterates over each element in the original array, applies a provided function, and collects the results into a new array. This concise and powerful utility is particularly ...
๐ŸŒ
React
react.dev โ€บ learn โ€บ rendering-lists
Rendering Lists โ€“ React
How to move data out of components and into data structures like arrays and objects. How to generate sets of similar components with JavaScriptโ€™s map().
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-render-lists-in-react
How to Render Lists in React using array.map()
April 10, 2023 - import React from 'react'; const applicants = [ { name: 'Joe', work: 'freelance-developer', blogs: '54', websites: '32', hackathons: '6', location: 'morocco', id: '0', }, { name: 'janet', work: 'fullstack-developer', blogs: '34', websites: '12', hackathons: '8', location: 'Mozambique', id: '1', }, ]; function App() { return ( <> {applicants.map(function(applicant) { return ( <div key={applicant.id}> <p>Applicant Name: {applicant.name}</p> <p>Applicant location: {applicant.location}</p> <p>Hackathons participated: {applicant.hackathons}</p> </div> ) })} </> ); }; export default App;
Top answer
1 of 4
1

You can use map to simplify it. The tricky bit will be the calling of Update with different number of parameters, but that too can be achieved using another map.

const columns = ['Title', 'Author', 'Rating'];

export const BookshelfListRow = (props) => {
  return (
    <tr className="table-row">
    {
      columns.map((column, i) => (
        <td>
          <input onChange={ e =>
                   props.Update(...[                                            // the parameters to Update consist of
                     ...columns.slice(0, i).map(column => props.book[column]),  // the column values from the start until the current column, map is used here to get the values for those columns
                     e.target.value                                             // and the input value
                   ])
                 }
                 placeholder={ props.book[column] } />
        </td>
      ))
    }
    </tr>
  )
}

Another approach:

The Update function is a mess. It can be a lot simpler if it just takes the column that was changed and the value as there is no need for it to send all those props back to the server if only one was changed, like so (this uses computed property names):

const Update = (column, value) =>                                         // takes the column that was changed and the value
  axios.put('http://localhost:4001/books/update', { [column]: value });   // update only that column

Then the rendering will be much simpler also, like so:

const columns = ['Title', 'Author', 'Rating'];

export const BookshelfListRow = (props) => {
  return (
    <tr className="table-row">
    {
      columns.map((column, i) => (
        <td>
          <input onChange={ e => props.Update(column, e.target.value) } placeholder={ props.book[column] } />
        </td>
      ))
    }
    </tr>
  )
}
2 of 4
0

If you're using the keys of props.book, you can try something like this:

import React from "react";

const BookshelfListRow = props => {
  const args = [];
  return (
    <tr className="table-row">
      {Object.keys(props.book).map((key, idx) => {
        if(idx > 0) {
          args.unshift(key);
        }
        const argsCopy = [...args];
        return (
          <td>
            <input
              onChange={e => {
                props.Update(...argsCopy, e.target.value);
              }}
              placeholder={props.book[key]}
            />
          </td>
        );
      })}
    </tr>
  );
};

export default BookshelfListRow;

Otherwise, you can use an array like the one you suggested (const columns = ['Title', 'Author', 'Rating']) and take each value and add it to a copy with each map loop.

๐ŸŒ
Medium
himadrikhali.medium.com โ€บ list-in-react-how-to-use-map-function-in-react-basic-example-of-map-function-in-react-f85381821960
List in React ? How to use map function in react ? Basic Example of map function in React. | by Himadrikhali | Medium
May 29, 2023 - The JavaScript map() array method is generally the preferred method. Keys allow React to keep track of elements. This way, if an item is updated or removed, only that item will be re-rendered instead of the entire list. Keys need to be unique to each sibling. But they can be duplicated globally. ... 2. We define a functional component called DPS.
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ how to use the map() function in react js
How to Use the Map() Function in React JS
June 11, 2025 - It simplifies the array data manipulation process by being a built-in method. When invoked on an array, the map() function applies the given callback function to every element, resulting in a new array with the transformed elements.