0

I am making a clothing store, I made the product presentation page. it works fine, but when i reload the page, state reverts to the initial state and returned to the console "y a rien pour le remplir". as the componentDidMount did not work. ---the image before reloadenter image description here

---the image after reload enter image description here

componentDidMount(){
       const {load_state} = this.props // You Need Thi
    let request = new FormData;
    request.append("getters_produit","true");
    Axios.post('http://localhost/e_commerce/src/php/get.php',request).then(function(reponce){
        //handle succes
            load_state(reponce.data.les_produit);
    }).catch(function(error){
        alert(error);
    }).then(function(){
        //always executed
    });
}

render(){
return (<div className="les_produit">
{(this.props.state.liste_produit == "none") ? console.log("y a rien pour le remplir") :this.romplir_page(this.props.state.liste_produit) }
</div>)}
sifo
  • 33
  • 5
  • Interesting. Please put a `console.log("here")` in `componentDidMount` after the axios, to see if the problem is the axios response or the componentDidMount func. – Eldshe Jan 06 '21 at 14:28
  • in your if statement you are doing "this.props.state.liste_produit". I'm not sure where liste_produit comes from (props or state) but you have them both in your if statement. I think it should be this.state.liste_produit or this.props.liste_produit – TimeParadox Jan 06 '21 at 14:37
  • @Eldshe yes the problem is there, the first time it works well and make the request change the state, and when reload the page componentDidMount not work – sifo Jan 09 '21 at 09:48
  • @TimeParadox I did console.log (props), and the result is: //////////// `Object history: {length: 3, action: "PUSH", location: {…}, createHref: ƒ, push: ƒ, …} load_state: reponce_liste_produit => {…} location: {pathname: "/produit", search: "", hash: "", state: null, key: "8zqm33"} match: {path: "/produit", url: "/produit", isExact: true, params: {…}} state: {liste_produit: Array(5), profile: "nono"} staticContext: undefined __proto__: Object` – sifo Jan 09 '21 at 10:06
  • if the problems is that the componentdidmount is not called when you reload we need more to see more code. where are you rendering this component, do you have two componentdidmounts, do parent componentdidmounts work, how can the render work but the componentDidMount not. also I'm not sure if you should put an object named "state" in your props. – TimeParadox Jan 09 '21 at 12:23

0 Answers0