this.todos.map为什么一直报错?

import React from 'react'
import PropTypes from 'prop-types'
import Todo from './Todo'

class TodoList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            value: null,
        };
        this.todos = [
            {
                id: 'ccaac',
                value: '加鲁鲁',
                adhere: '粘贴'
            }
        ];
        this.todos.map(todo => (
            console.log(todo)
        ))
    }

    render() {
        let todos = this.todos
        return {this.todos.map(todo => (
                <Todo id={todo.id} />
        ))}
    }
}

export default TodoList;
import React, { Component } from 'react';

class Todo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            value: null,
        };
    }

    render() {
        return <div className="square" onClick={() => alert('click')}>
            {this.props.id}
        </div>
    }
}

export default Todo;
阅读 1.9k
1 个回答

return后面不是得这样写吗?你确定是map报错,不是render报错?0-0

    return (
            <div>
                {this.todos.map(todo => (
                    <Todo id={todo.id} />
                ))}
            </div>
        )
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题