Skip to content

Instantly share code, notes, and snippets.

@refayathaque
Created August 31, 2020 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refayathaque/6a8da967e3d4feb540562ffc785c96d4 to your computer and use it in GitHub Desktop.
Save refayathaque/6a8da967e3d4feb540562ffc785c96d4 to your computer and use it in GitHub Desktop.
Input.js
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