I am new to react and I am trying to develop a simple web app with it but I get an error. My Constructor is called twice when I load a class component can you help?
Home.js
import React from 'react'
import Land from "../Land";
function Home() {
return (
<div>
<h1>Home!</h1>
<Land/>
</div>
)
}
export default Home
Partial Land.js
import React, { Component } from 'react'
import Login from "./Login";
class Land extends Component {
constructor(props) {
super(props)
this.state = {
}
console.log("LAND")
}
the log LAND is hit twice.
In some of the components I wish to make an API call that hits a DB but I only want to hit it once.
In many instances using componentDidMount
is not convenient because props only appear after componentDidMount
therefor id like to do the call in render
(I will not be using setState, that would cause a reload of render).
Thanks in advance
Hold up
) const url = "/events/"+props.event_id; console.log(url);``` – Pedro Dimas Aug 09 '20 at 00:17