Created
January 21, 2020 18:53
-
-
Save darksh3ll/d281f7f58c4aa5d28814519216e813a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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