Input of Skills

ReactReactBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this challenge we will develop react tag input component which can add tags without any external library.
Only with just one component you can have an input box with the capability to input tags or keywords.
In input of tags component, there will be only one state which will carry all the user inputs with the help of onKeyUp JavaScript event.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL react(("`React`")) -.-> react/FundamentalsGroup(["`Fundamentals`"]) react(("`React`")) -.-> react/AdvancedConceptsGroup(["`Advanced Concepts`"]) react(("`React`")) -.-> react/StateManagementGroup(["`State Management`"]) react(("`React`")) -.-> react/StylingGroup(["`Styling`"]) react/FundamentalsGroup -.-> react/jsx("`JSX`") react/FundamentalsGroup -.-> react/event_handling("`Handling Events`") react/FundamentalsGroup -.-> react/list_keys("`Lists and Keys`") react/AdvancedConceptsGroup -.-> react/hooks("`React Hooks`") react/StateManagementGroup -.-> react/use_state_reducer("`Using useState and useReducer`") react/StylingGroup -.-> react/css_in_react("`CSS in React`") subgraph Lab Skills react/jsx -.-> lab-67590{{"`Input of Skills`"}} react/event_handling -.-> lab-67590{{"`Input of Skills`"}} react/list_keys -.-> lab-67590{{"`Input of Skills`"}} react/hooks -.-> lab-67590{{"`Input of Skills`"}} react/use_state_reducer -.-> lab-67590{{"`Input of Skills`"}} react/css_in_react -.-> lab-67590{{"`Input of Skills`"}} end

Input of Skills

To get started, open the editor. You can see the following files from your editor.

├── public
├── src
│   ├── components
│   │   └── TagInput.js
│   ├── App.css
│   ├── App.js
│   ├── index.css
│   └── index.js
├── package-lock.json
└── package.json

Requirements

  • To install the project dependencies, use the following command:

    npm i
  • Please complete this challenge in the src/component/TagInput.js file.

  • The handleAddTag function is called when a key is pressed in the input field. If the key is not the Enter key, the function returns early and does nothing. Otherwise, it checks the input value and adds it to the tags state if it is not empty and hasn't already been added. Then, it clears the input field.

  • The onDeleteTag function is called when a tag is clicked. It filters the tags state to remove the clicked tag and updates the state with the filtered tags.

Example

Once you have completed the code, run it with the following command:

npm start

The finished result is as follows:

finished

Summary

Congratulations! You have completed the Input of Skills. You can practice more challenge in LabEx to improve your skills.

Other React Tutorials you may like