javascript - Array in React state won't map -


i have setting state:

constructor() {   super();   this.state = {     isloggedin: false,     loginshowing: false,     user: null,     programs: ['cool','guy','nice']   } } 

... when try in render

{this.state.programs.map(program =>   <h1>{program}</h1> )} 

nothing shows on page. if put asdf: '123' in state , print <h1> {this.state.asdf} </h1>, work. know why mapping array in state doesn't render? thanks.

i'm running react on macos sierra 10.12.6, react ^15.6.1.

edit: seems code causing it:

  componentdidmount() {     if(localstorage.getitem('accountdata') != null) {       this.authenticatetoken(localstorage.getitem('accountdata'));     }   } 

i don't know how affecting render is.

i have tried code , worked me:

class custominput extends react.component {   constructor() {   super();   this.state = {     isloggedin: false,     loginshowing: false,     user: null,     programs: ['cool','guy','nice']   } }    render() {      return <div>      {this.state.programs.map(program =>         <h1>{program}</h1>       )}     </div>   } } 

https://stackblitz.com/edit/react-jmfafj


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -