DEV Community

Anohjp
Anohjp

Posted on

TypeError: produits.map is not a function

TypeError: produits.map is not a function

Hi all

I'm new in react js. I followed this tuto "https://pusher.com/tutorials/consume-restful-api-react" and i tried to adapt for me.
here is my code content:

file App.js

import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import './bootstrap.min.css';
import Produits from './components/produits';

class App extends Component{

render(){
return(

)
}

state = {
produits : []
};

componentDidMount(){
fetch('https://servitis.com/apirest_php/actions/read.php')
.then(res => res.json())
.then((data) => {
this.setState({ produits: data })
})
.catch(console.log)
}

}

export default App;

File Produits.js

import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import './bootstrap.min.css';
import Produits from './components/produits';

class App extends Component{

render(){
return(

)
}

state = {
produits : []
};

componentDidMount(){
fetch('https://servitis.com/apirest_php/actions/read.php')
.then(res => res.json())
.then((data) => {
this.setState({ produits: data })
})
.catch(console.log)
}

}

export default App;

After compiation, here is error genereted : TypeError: produits.map is not a function

So, i need your held.
Thank you!

Top comments (1)

Collapse
 
mitchelln11 profile image
mitchelln11

Are you even using the .map function?

I came across the same error. It was working for me yesterday, and now .map is not a function.