-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
100 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
11 changes: 10 additions & 1 deletion
11
...management-naive-dont-copy/create/page.js → ...anagement-naive-dont-copy/create/page.tsx
This file contains 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
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import createOrUpdateCookie from './actions'; | ||
|
||
type Props = { | ||
fruitId: number; | ||
}; | ||
|
||
export default function FruitCommentForm(props: Props) { | ||
const [comment, setComment] = useState(''); | ||
|
||
// Option 2: If you use a function declared elsewhere, you need to define the type of `event` | ||
// function handleChange(event: ChangeEvent<HTMLTextAreaElement>) { | ||
// setComment(event.currentTarget.value) | ||
// } | ||
|
||
return ( | ||
<form> | ||
<textarea | ||
value={comment} | ||
// Option 1: Inline function does not require type | ||
onChange={(event) => setComment(event.currentTarget.value)} | ||
|
||
// Option 2: If you use a function declared elsewhere... | ||
// onChange={handleChange} | ||
/> | ||
<button formAction={() => createOrUpdateCookie(props.fruitId, comment)}> | ||
Add comment | ||
</button> | ||
</form> | ||
); | ||
} |
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sjson from 'secure-json-parse'; | ||
import { FruitComment } from '../app/fruits/[fruitId]/actions'; | ||
|
||
export function parseJson(json: string | undefined) { | ||
if (!json) return undefined; | ||
try { | ||
// `as` is called a type assertion | ||
// | ||
// This tells TypeScript that you know better about | ||
// what the type is | ||
// | ||
// Slightly unsafe, because we don't really absolutely | ||
// know what the type is coming back from sjson (it | ||
// tells us that it is `any`) | ||
return sjson(json) as FruitComment[]; | ||
} catch { | ||
return undefined; | ||
} | ||
} |
This file contains 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