6

Stuck with sample code from book learning React. Code below throwing Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of 'Card'.. Checked SO (there are couple with similar issues) but I couldn't figure out what's wrong here.

import React, {Component} from 'react';
import {render} from 'react-dom';
import CheckList from './CheckList';

class Card extends Component {
    render() {
        return (
            <div className="card">
                <div className="card__title">{this.props.title}</div>
                <div className="card__details">
                    {this.props.description}
                    <CheckList cardId={this.props.id} tasks={this.props.tasks} />
                </div>
            </div>
        );
    }
}

CheckList.js

class CheckList extends Component{
    render(){
          let tasks = this.props.tasks.map((task)=>(
            <li className="checklist__task">
                <input type="checkbox" defaultChecked={task.done} />
                {task.name}

            </li>
        ));
        return (
            <div className="checklist">
                <ul>{tasks}</ul>
            </div>
        );
    }
}
1

2 Answers 2

12

You need to export CheckList

Change your class definition to:

export default class CheckList extends Component{
Sign up to request clarification or add additional context in comments.

1 Comment

Aha. This is it. As soon as I did export default CheckList; this worked fine.
0

Change the code as following.

from

class CheckList extends Component{
    render(){
          let tasks = this.props.tasks.map((task)=>(
            <li className="checklist__task">
                <input type="checkbox" defaultChecked={task.done} />
                {task.name}

            </li>
        ));
        return (
            <div className="checklist">
                <ul>{tasks}</ul>
            </div>
        );
    }
}

export class CheckList

to

export default class CheckList extends Component{
    render(){
          let tasks = this.props.tasks.map((task)=>(
            <li className="checklist__task">
                <input type="checkbox" defaultChecked={task.done} />
                {task.name}

            </li>
        ));
        return (
            <div className="checklist">
                <ul>{tasks}</ul>
            </div>
        );
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.