Logo


How to make data-list in React JS without using Data-List Attribute


In this article,we are going to make custom Data-List ,This codes helps the developers to modify and displaying the elements in a particular way or similar to data-list.
The Data-List Component is displayed below

1import React from 'react'
2import './styles.css'
3const MOCK_DATA = [
4  {
5    id: 1,
6    todoItem: 'Buy Food',
7    name: 'Moiz'
8  },
9  {
10    id: 2,
11    todoItem: 'Eat Dinner',
12    name: 'Alex'
13  },
14  {
15    id: 3,
16    todoItem: 'Clean the House',
17    name: 'hi'
18  },
19  {
20    id: 4,
21    todoItem: 'Go for a Walk'
22  }
23]
24
25export default class DataList extends React.Component {
26  constructor (props) {
27    super(props)
28    this.state = {
29      value: ''
30    }
31  }
32  changeHandler = e => {
33    this.setState({
34      value: e.target.value
35    })
36  }
37  render () {
38    return (
39      <div>
40        <ul>
41          {MOCK_DATA.map(todo => (
42            <li key={todo.id}>{todo.todoItem}</li>
43          ))}
44        </ul>
45        
46        
47          <div class='select-editable'>
48            <select
49              name='tempratureSource3'
50              list='source'
51              className='form-control'
52              // size="4"
53              placeholder='Source'
54              type='text'
55              // value={saveVitalsModal.tempratureSource}
56              onChange={e => this.changeHandler(e)}
57            >
58              {MOCK_DATA &&
59                MOCK_DATA.map((s, i) => <option key={i}>{s.name}</option>)}
60            </select>
61            <input
62              type='text'
63              name='format3'
64              onChange={this.changeHandler}
65              value={this.state.value}
66            />
67          </div>
68        
69      <div/>
70    )
71  }
72}

App.js file is displayed below:

1import React from "react";
2import DataList from './Datalist'
3 
4class App extends React.Component {
5  render() {
6    return <h1><DataList /></h1>;
7  }
8}
9 
10export default App;

Here is the link of live example which we done so far:
Click here

About

Moiz is a software engineer from Arid University with a passion for writing tech tutorials and doing coding. I am continously produce JavaScript and other web development technology tutorials in concepts through easy-to-understand explanations written in plain English.I have expertise in next js ,react js ,javascript,html,bootstrap and node js.

Follow him on Twitter

Hassan is a software engineer from kohat university of science and technology with a passion for writing tech tutorials and doing javascript practices on daily basis.I have expertise in next js ,react js ,javascript,html,bootstrap and node js. Problem Solving and making concpets is my strong point.

Follow him on Twitter

Tags

Click to see all tutorials tagged with:

© Copyright 2023 Pak Annonymous | Back To Homepage | Privacy Policy
Share