Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try using a loop to render repetitive data #15

Open
oliverjam opened this issue Jun 9, 2022 · 1 comment
Open

Try using a loop to render repetitive data #15

oliverjam opened this issue Jun 9, 2022 · 1 comment

Comments

@oliverjam
Copy link

You have a lot of repeated inputs in this component

<label htmlFor="Adventure">
Adventure
<input
checked={category === "Adventure"}
type="radio"
name="categories"
id="Adventure"
value="Adventure"
onChange={(event) => setCategory(event.target.value)}
/>
</label>

Since each one maps to an entry in the categories object

const categories = {
Action: 28,
Adventure: 12,

You could loop over that to generate the inputs, something like this:

Object.keys(categories).map((key) => (
  <label htmlFor={key}> 
   {key} 
   <input 
     checked={category === key} 
     type="radio" 
     name="categories" 
     id={key}
     value={key}
     onChange={(event) => setCategory(event.target.value)} 
   /> 
 </label> 
))
@minju25kim
Copy link
Contributor

remove repetitive data and change it as loop inside {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants