Communicate Between Components | React

Communicate Between Components For parent-child communication, simply pass props. For child-parent communication: Say your GroceryList component has a list of items generated through an array. When a list item is clicked, you want to display its name: var GroceryList = React.createClass({ handleClick: function(i) { console.log(‘You clicked: ‘ + this.props.items[i]); }, render: function() { return (…

Read More

Expose Component Functions | React

Expose Component Functions There’s another (uncommon) way of communicating between components: simply expose a method on the child component for the parent to call. Say a list of todos, which upon clicking get removed. If there’s only one unfinished todo left, animate it: var Todo = React.createClass({ render: function() { return {this.props.title}; }, //this component…

Read More

Interactivity and Dynamic UIs | React

You’ve already learned how to display data with React. Now let’s look at how to make our UIs interactive. A Simple Example # var LikeButton = React.createClass({ getInitialState: function() { return {liked: false}; }, handleClick: function(event) { this.setState({liked: !this.state.liked}); }, render: function() { var text = this.state.liked ? ‘like’ : ‘haven’t liked’; return ( You…

Read More

Reusable Components | React

When designing interfaces, break down the common design elements (buttons, form fields, layout components, etc.) into reusable components with well-defined interfaces. That way, the next time you need to build some UI, you can write much less code. This means faster development time, fewer bugs, and fewer bytes down the wire. Prop Validation # As…

Read More

Event Delegation

How JavaScript Event Delegation Works content One of the hot methodologies in the JavaScript world is event delegation, and for good reason.  Event delegation allows you to avoid adding event listeners to specific nodes;  instead, the event listener is added to one parent.  That event listener analyzes bubbled events to find a match on child…

Read More

Programming Sucks

Every friend I have with a job that involves picking up something heavier than a laptop more than twice a week eventually finds a way to slip something like this into conversation: “Bro, you don’t work hard. I just worked a 4700-hour week digging a tunnel under Mordor with a screwdriver.” They have a point….

Read More