Created
August 31, 2020 21:41
-
-
Save refayathaque/6a8da967e3d4feb540562ffc785c96d4 to your computer and use it in GitHub Desktop.
Input.js
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
import React, { Fragment } from 'react' | |
import useFetchPosts from '../Hooks/useFetchPosts'; | |
import useFetchComments from '../Hooks/useFetchComments'; | |
export default () => { | |
const [ setUserIdPosts ] = useFetchPosts(); | |
const [ setPostIdComments ] = useFetchComments(); | |
const setUserIdInCustomHooks = (id) => { | |
setUserIdPosts(id) | |
setPostIdComments(id) | |
} | |
const renderDropdownValues = () => { | |
const ids = [ 'None selected', 1, 2, 3, 4, 5, 6, 7, 8, 9 , 10 ]; | |
return ids.map((id, index) => | |
<option key={ index } value={ id }>{ id }</option> | |
); | |
} | |
return ( | |
<Fragment> | |
<h3>Input component</h3> | |
<label>Select userId (posts) / postId (comments) </label> | |
<select onChange={({ target }) => setUserIdInCustomHooks(target.value)}> | |
{ renderDropdownValues() } | |
</select> | |
</Fragment> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment