React+redux official instance Todo from the simplest introduction (5)--check

Source: Internet
Author: User

The previous article "change" to achieve, the last function--"check"!

This check is a slightly more complex function, the official implementation is a filter array effect, and then show that there are 3 states, all,completed,active.

To implement these three states, we need to implement a feature ahead of time, which is to give each of the displayed subcomponents a property (method) that can change the state of the completed or active---so that there is something to look for (filter)

Old rules

1. State of Declaration

2. Actions

3, Reducer

4, Component

Okay, look at the effect.

There seems to be a bad one, the official website is a diagonal ah! Don't worry, just a class question, let's add

It's done!

Here, adding state to each subcomponent has been implemented, and we should ' check ' (filter) the next step.

Then write a component to implement the filter array, which is displayed according to the completed state of the subassembly.

First we implement the bottom view, and then slowly add the function

Put the footer here, because it is to use the state of the surface, it is very convenient to relate.

Already shown, add styles and features now.

To add a style first:

The simple style is displayed, add the function below

First we're going to set a different function for the three states to get the array we want.

After writing here, the following is the call to this, the corresponding will not have to say more

Here's a brief, in Mainsection, there's a

Return all,completed,active three states, below through him to call his return value! The filter usage is not much to say.

In footer, pass in the filter parameter

This onshow function comes from

The function of this method is to change the value of the filter, which is from footer.

By clicking, passing in the corresponding filter, then this filter, you can filter the array

The whole process seems simple, actually contains a lot of knowledge, good, to here, basically realized the function of check, now look at the effect bar!

Here, we have achieved the increase-delete-change-check, four functions, of course, there are other features on the official website, the next last time, we will add all the functions, in fact, it is not difficult to find, in fact, to achieve a function is then the matter

Declaring State a constant

Contract a function that will be executed

Perform function Update store

View level write a good way, one layer at a level to pass! (Logical execution is generally written in the bottom view, the prescribed method is generally in its parent ...) )

React+redux official instance Todo from the simplest introduction (5)--check

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.