Building a simple component in React.js

Building a simple component in React.js

Building a simple component in React.js: In the last post we started building some React.js components for searching for a company name and displaying matching names.

In the last post we started building some React.js components for searching for a company name and displaying matching names. In this post, we are going to handle the search request before displaying the results in the final post.

The first thing we need to do is change the Criteria component to handle a click event on the button.

  • Line 13 creates a click event on the “Go” button that is handled by a handleClick function
  • In the handleClick function, line 5 gets the search criteria from the search box
  • Line 6 sets a “onSearch” property to the criteria that the parent component can pick up on
var Criteria = React.createClass({
  handleClick: function(e) {
    var criteria;
    e.preventDefault();
    criteria = React.findDOMNode(this.refs.search).value.trim();
    this.props.onSearch(criteria);
  },
  render: function() {
    return (
      <div>
        <input ref="search" type="search" placeholder="Search criteria" />
        <button onClick={this.handleClick}>Go</button>
      </div>
    );
  }
});

The next thing to do is to wire up the onSearch property in the Search component and react to it.

  • Line 9 wires the onSearch property in the instance of the Criteria component to the handleSearch function
  • For now, the implementation of the handleSearch function is to simply output the search critieria to the console. We will expand on this in our next post

react

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

What are hooks in React JS? - INFO AT ONE

In this article, you will learn what are hooks in React JS? and when to use react hooks? Also, we will see the react hooks example.

Build a simple React Native Pokemon app with React-Navigation

As we start learning new technologies we want to start building something or work on a simple project to get a better understanding of the technology.

Share Code Between React Native and React JS

React provides support for the server-side and frontend. Today, React development services are in demand as more and more organizations are considering software solutions that are crafted from the framework.

Validating React Forms With React-Hook-Form

In this article we will learn how to Validating React Forms With React-Hook-Form . Validating inputs is very often required. For example, when you want to make sure two passwords inputs are the same, an email input should in fact be an email or that the input is not too long