Skip to content

Instantly share code, notes, and snippets.

@darksh3ll
Created January 21, 2020 18:53
Show Gist options
  • Save darksh3ll/d281f7f58c4aa5d28814519216e813a2 to your computer and use it in GitHub Desktop.
Save darksh3ll/d281f7f58c4aa5d28814519216e813a2 to your computer and use it in GitHub Desktop.
mport React, { useEffect,useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'
import axios from 'axios'
const Testing = () => {
const [value,setValue] = useState('')
const dispatch = useDispatch();
const users = useSelector(state => state.userReducers.data);
useEffect(() => {
axios
.get('https://jsonplaceholder.typicode.com/users/')
.then(result => dispatch({ type: 'FETCH_DATA', payload: result.data }))
.catch(error => { console.log(error) })
}, [dispatch]);
return (
<div>
<input onChange={(e) => setValue(e.target.value)} type="text" placeholder="search"/>
{users.filter(x => x.name.includes(value)).map(user => <p key={user.id}>{user.name}</p>)}
</div>
)
};
export default Testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment