Y
Y
Yzurgzd2020-06-09 13:59:16
React
Yzurgzd, 2020-06-09 13:59:16

Why swears at map?

const appsService = new AppsService();

constructor(props) {
    super(props);
    this.state = {
      apps: [],
    };
  }

  componentDidMount() {
    var self = this;

    const {
      match: { params },
    } = this.props;

    appsService.getApp(params.pk).then(function (result) {
      console.log(result);
      self.setState({ apps: result });
    });

getApp
getApp(pk) {
    const url = `${API_URL}/api/apps/${pk}/`;
    return axios.get(url).then((response) => response.data);


It is displayed correctly in the console, but when outputting to the component, the error is Uncaught TypeError: this.state.apps.map is not a function
I output it like this
{this.state.apps.map((app) => (
    <h1>{app.title}</h1>
))}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-06-09
@Yzurgzd

appsService.getApp(params.pk).then(function (result) {
      console.log(result);  // ?

is it an array, not a string or an object?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question