import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import {Router, Route, Link} from 'react-router-dom'; import createBrowserHistory from 'history/createBrowserHistory'; const history = createBrowserHistory(); const page = function(text){return(<div>{text}</div>)} class People extends Component{ constructor(props){ super(props); this.state = {}; // this.self = this.bind(this); }; componentDidMount(){ } render(){ var people = this.props.people; var ul; return (<div><Router history={history}> <div> {ul = this.props.people.map((item,i)=>{ var k = Object.keys(item) k = k[0] var li; li = <li key={i}><Link to ={k.toLowerCase().trim().replace(" ","-")} >{k}</Link> </li>; console.log(k); return li;}) console.log('descriptions'); } </div></Router></div>) } } export default People; 

gives a syntax error, I don’t understand, everything seems to be normal, maybe I don’t understand something conceptually, how the code works, some detail.

Failed to compile ./src/People.js Syntax error: C: /Users/Dima/Desktop/myReact/my-app/src/People.js: Unexpected token, expected} (36: 2)

 34 | 35 | return li;}) > 36 | console.log('descriptions'); | ^ 37 | 38 | } 39 | </div></Router></div>) 
  • Add to the question or all the code, or at least an error, but rather both. - Ilya
  • It seems to me that the problem here is that you assign the returned html to the variable, and then you also try to call console.log('descriptions'); inside the markup console.log('descriptions'); . In this case, this is not a callback, but simply a js code in the markup without the necessary tags. What do you want to do? Maybe it is out of place there? - Ilya
  • The result should be a component that can iterate through the array and make it a menu of links to pages (this is what the ul variable has) and after declaring this variable, routes that follow the links should follow. - Dmitriy Scherbakov
  • I can’t find any references to writing functions after map , but I suspect that the problem is that jsx converts objects in a special way, which causes syntax errors. Look in the documentation, it seems to me that this is what you want to do: reacttraining.com/react-router/web/example/route-config Here is a similar article in Russian: habrahabr.ru/post/329996 and codepen.io/ pshrmn / pen / YZXZqM - Ilya
  • Thanks for the answer, Ilya, what was needed. - Dmitriy Scherbakov Nov.

0