I'm making a litte app(a list of topics) where i use checkbox to delete some topic but when i start the app the console said "Cannot read property 'checked' of undefined" i read on some post that it could be cause i rewrite the check box bur i don't see where.
can you help ?
import React, { Component, PropTypes } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { Topics } from '../api/topic.js';
import Topic from './Topic.jsx';
class AppTopic extends Component {
toggleChecked() {
// Set the checked property to the opposite of its current value
Topics.update(this.props.topic._id, {
$set: { checked: !this.props.topic.checked },
});
}
deleteThisTopic() {
Topics.remove(this.props.topic._id);
}
renderTopics() {
return this.props.topics.map((topic) => (
<Topic key={topic._id} topic={topic} />
));
}
render() {
// Give tasks a different className when they are checked off,
// so that we can style them nicely in CSS
const topicClassName = this.props.topic.checked ? 'checked' : '';
return (
<li className={topicClassName}>
<button className="delete" onClick={this.deleteThisTopic.bind(this)}>
×
</button>
<input
type="checkbox"
readOnly
checked={this.props.topic.checked}
onClick={this.toggleChecked.bind(this)}
/>
<span className="text">{this.renderTopics()}</span>
</li>
);
}
}
AppTopic.propTypes = {
topics: PropTypes.array.isRequired
};
export default createContainer(() => {
return {
topics: Topics.find({}).fetch(),
};
}, AppTopic);
Aucun commentaire:
Enregistrer un commentaire