JavaScript State in react is not rendering to the screen react state rendering,react state not rendering,react state change

At first rename this.State to this.state, state definition should be lowercase.

In app component you render object in <div /> jsx elemnt, it is incorrect. Try to map your messages and return separate element for each entity:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import axios from 'axios';

class App extends Component {
  constructor(props) {
    super(props);
    this.State = {
      messages:[]
    }
  }
  componentDidMount() {
    axios.get('/patient/billing_get')
      .then((result) => {
        const messages = result.data
        console.log(messages);
        this.setState({
          messages: [...messages]
        })
      })
  }

  render() {
   const { messages }  = this.state;
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
          <div>
           {messages.map(item => <span key={messages.indexOf(item)}>{item}</span>)}
          </div>
         </p>
     </div>
    );
  }
}

export default App;

Edit validate html

render() {
   const { messages }  = this.state;
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <div className="App-intro">
          <p>To get started, edit <code>src/App.js</code> and save to reload.</p>
          <div>
           {messages.map(item => <span key={messages.indexOf(item)}>{item}</span>)}
          </div>
         </div>
     </div>
    );
  }
Answer:1

You cannot render the state object (note: lowercase, not State!), the following will never work:

<div>{this.state}</div>

Instead, pull off properties like the following:

class Example extends React.Component {
  constructor () {
    super()
    this.state = {
      messages: ['hi', 'bye']
    }
  }
  
  render () {
    // pull off messages array from state, then map over it to get each message
    const { messages } = this.state 
    return (
      <div>
        {messages.map(message => (
          <div>{message}</div>
        ))}
      </div>
    )
  }
}

ReactDOM.render(
 <Example />, 
 document.getElementById('root')
)
<div id='root'></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
Answer:2

I am creating an app in where a user have to enter their car details.I've created a form and have successfully able to update the input datas into the database on Parse.com.I want to use the database ...

I am creating an app in where a user have to enter their car details.I've created a form and have successfully able to update the input datas into the database on Parse.com.I want to use the database ...

  1. autocomplete suggestions in angularjs
  2. autocomplete suggestions in excel
  3. autocomplete suggestions in php
  4. suggestions for autocomplete
  5. remove autocomplete suggestions from

My firebase method onAuthStateChanged() trigger several times when I sign in and out using firebase-authentication according to console.log. Isn't it supposed to trigger only once at login and once at ...

My firebase method onAuthStateChanged() trigger several times when I sign in and out using firebase-authentication according to console.log. Isn't it supposed to trigger only once at login and once at ...

var garbage = document.getElementById("garbage"); garbage.addEventListener("click",function(){ garbage.style.color = "#66c144"; } <link href="https://use.fontawesome.com/releases/v5.0.10/...

var garbage = document.getElementById("garbage"); garbage.addEventListener("click",function(){ garbage.style.color = "#66c144"; } <link href="https://use.fontawesome.com/releases/v5.0.10/...

  1. change color font awesome
  2. change color font html
  3. change color font awesome icon
  4. change color font in outlook
  5. change color font latex
  6. change color font wordpress
  7. change color font css
  8. change color font photoshop
  9. change color font on iphone
  10. change color font instagram
  11. change color font in facebook
  12. change color font online
  13. change color font visual studio
  14. change color font indesign
  15. change color font in word
  16. change color font awesome icon on hover
  17. change color font whatsapp
  18. change color font ml
  19. change color font instagram story
  20. change color font excel formula

I have a main.js with React.render( <h1>Hello, world!</h1>, document.getElementById('myDiv') ); I am using CodeKit, and it spits out the error: Unexpected token: ...

I have a main.js with React.render( <h1>Hello, world!</h1>, document.getElementById('myDiv') ); I am using CodeKit, and it spits out the error: Unexpected token: ...

  1. react unexpected token expected
  2. react unexpected token ' '
  3. react unexpected token in json at position 0
  4. react unexpected token import
  5. react unexpected token export
  6. react unexpected token return
  7. react unexpected token if
  8. react unexpected token fragment
  9. react unexpected token svg
  10. react unexpected token arrow function
  11. react unexpected token function
  12. react unexpected token const
  13. react unexpected token state u003d