Skip to content

Instantly share code, notes, and snippets.

View BrianCortes's full-sized avatar

Brian Fernando Cortes Almonacid BrianCortes

View GitHub Profile
@BrianCortes
BrianCortes / App.js
Created May 15, 2017 01:22
Application core
import React, { Component } from 'react';
import UserProfile from './components/UserProfile/UserProfile'
import Heart from './components/Heart/Heart'
import Comments from './components/Comments/Comments'
import './App.css';
class App extends Component {
state = {
LikesNumber: 0,
ComentsNumber: 1,
@BrianCortes
BrianCortes / App.js
Created May 16, 2017 00:13
import react and components
import React, { Component } from 'react';
import UserProfile from './components/UserProfile/UserProfile'
import Heart from './components/Heart/Heart'
import Comments from './components/Comments/Comments'
import './App.css';
@BrianCortes
BrianCortes / App.js
Last active May 16, 2017 01:01
create react component
class App extends Component {
state = {
LikesNumber: 0,
ComentsNumber: 1,
Comments: [{
value: 'React is Awesome !!'
}]
}
...
@BrianCortes
BrianCortes / App.js
Created May 16, 2017 02:12
function for change state
clickHeart = () => {
const likes = this.state.LikesNumber
this.setState({LikesNumber: likes + 1})
}
addComment = (newValue) => {
const comments = this.state.ComentsNumber
const arrayComments = this.state.Comments
const newComment = {
value: newValue
}
arrayComments.push(newComment)
this.setState({ComentsNumber: comments + 1})
this.setState({Comments: arrayComments})
this.setState({valueText: ''})
render() {
return (
<div className="Container">
<UserProfile
img='https://pbs.twimg.com/profile_images/836333218924277760/iVzLr4c-.jpg'
Name='Monoku'
Likes={this.state.LikesNumber}
Comments={this.state.ComentsNumber}
/>
<Heart clickHeart={this.clickHeart}/>
<Comments
comments={this.state.Comments}
addComment={this.addComment}
changeText={this.changeText}
valueText={this.state.valueText}
/>
changeText = (value) => {
this.setState({valueText: value})
}
import React from 'react';
import PropTypes from 'prop-types';
import './Comments.css';
const Comments = ({comments, addComment, changeText, valueText}) => {
const handleChange = (event) => {
changeText(event.target.value)
}
const handleClick = () => {
addComment(valueText)
}
const CommentList = comments.map((element, index) => {
return(
<div className='Comments' key={index}>