0

why am i not seeing the data in my screen when I map over "this.state.viciados" if i can see the data in the console? I have seen this problem in stack overflow but the only answer in that qustion doesn't work.

class App extends Component {
  constructor(props) {
super(props);
this.state = {
  viciados: []
}

}


componentDidMount() {
this.getViciados();
}

 getViciados = _ => {
fetch("http://localhost:3000/dependentes")
  .then(response => response.json())
  .then(response => {
    this.setState({ viciados: response.data })
    //console.log(response.data);
  })
  .catch(err => console.log(err));
}



render() {


 const viciados = this.state.viciados.map(viciado => {
  console.log(viciado['id_viciados'], viciado["nome_viciado"]);
  <div key={viciado['id_viciados']}>{viciado["nome_viciado"]}</div>
});
return (
  <div className="App">
    {viciados}
  </div>
);
}
}

export default App;

1 Answer 1

1

You need to return data from map:

const viciados = this.state.viciados.map(viciado => {
  return <div key={viciado['id_viciados']}>{viciado["nome_viciado"]}</div>
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.