diff --git a/js/components/comments.jsx b/js/components/comments.jsx new file mode 100644 index 0000000..c24dda4 --- /dev/null +++ b/js/components/comments.jsx @@ -0,0 +1,27 @@ +import React from 'react'; +import CommentsList from './commentslist.jsx' +import CommentsForm from './commentsform.jsx' + +class Comments extends React.Component { + constructor(props){ + super(props); + this.state = { + comments: [] + } + this.addComment = this.addComment.bind(this); + } + addComment(value){ + this.state.comments.push(value); //this alone won't notify React to update the DOM + this.setState({ + comments: this.state.comments + }); + } + render(){ + return
+ + +
+ } +} + +export default Comments; diff --git a/js/components/commentsform.jsx b/js/components/commentsform.jsx new file mode 100644 index 0000000..2839a6f --- /dev/null +++ b/js/components/commentsform.jsx @@ -0,0 +1,20 @@ +import React from 'react'; + +class CommentsForm extends React.Component { + constructor(props){ + super(props); + this.handleSubmit = this.handleSubmit.bind(this); + } + handleSubmit(event){ + event.preventDefault(); + this.props.handleSubmit(this.refs.comment.value); + } + render() { + return
+ + +
+ } +} + +export default CommentsForm; diff --git a/js/components/commentslist.jsx b/js/components/commentslist.jsx new file mode 100644 index 0000000..4f12522 --- /dev/null +++ b/js/components/commentslist.jsx @@ -0,0 +1,14 @@ +import React from 'react'; + +class CommentsList extends React.Component { + render(){ + return + + } +} + +export default CommentsList; diff --git a/js/index.js b/js/index.js index 180dcf4..00044c4 100644 --- a/js/index.js +++ b/js/index.js @@ -1,7 +1,8 @@ import ReactDOM from 'react-dom'; import React from 'react'; +import Comments from './components/comments.jsx'; ReactDOM.render( -

Hello, world!

, + , document.querySelector('main') ); diff --git a/js/mylib.js b/js/mylib.js deleted file mode 100644 index b6aa956..0000000 --- a/js/mylib.js +++ /dev/null @@ -1,18 +0,0 @@ -const myFunc = function(){ - console.log('included!'); -} - -export default myFunc; - -const myFunc2 = function(){ - console.log('also included'); -} - -const unnecessary = function(){ - console.log('unnecessary'); -} - -export { - myFunc2, - unnecessary as omitme -}