Skip to content

Commit

Permalink
feat (frameworks/react): hook updates and reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Aug 29, 2024
1 parent db9e85b commit d9348dc
Show file tree
Hide file tree
Showing 38 changed files with 14,435 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions frameworks/react/6-2-hook-state-object/src/MedicationItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useState } from 'react'

export default function MedicationItem() {
const [medication, setMedication] = useState({
name: 'Velocirest',
description: 'Description of dosage and frequency of use of Velocirest.',
image: '/src/assets/medication1.svg',
dose: 200,
unity: 'mg',
quantity: 1,
frequency: 'day'
})

const { name, description, image, dose, unity, quantity, frequency } = medication;

return (
<div style={{ width: '300px', background: 'lightgray' }}>
<img src={image} width="50px" />
<h1>{name}</h1>
<p>{description}</p>
<p><b>dose:</b> {dose} {unity}</p>
<p><b>frequency:</b> {quantity} / {frequency}</p>
<button type="button" onClick={() => setMedication({ ...medication, quantity: quantity + 1 })}>
Increase quantity
</button>
</div>
);
}
7 changes: 7 additions & 0 deletions frameworks/react/6-2-hook-state-object/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ReactDOM from 'react-dom/client'
import MedicationItem from './MedicationItem.jsx'

const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
<MedicationItem />
)
12 changes: 12 additions & 0 deletions frameworks/react/7-hook-effect-object/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script src="src/main.jsx" type="module"></script>
</body>
</html>
Loading

0 comments on commit d9348dc

Please sign in to comment.