-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
257 additions
and
6 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
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,28 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
|
||
export default function Favorite({ name }) { | ||
const [isFavorite, setIsFavorite] = React.useState(null); | ||
|
||
React.useEffect(() => { | ||
const isFavorite = localStorage.getItem(`${name}:favorite`) === 'true'; | ||
|
||
setIsFavorite(isFavorite); | ||
}, [name]); | ||
|
||
const onClick = () => { | ||
setIsFavorite(!isFavorite); | ||
localStorage.setItem(`${name}:favorite`, String(!isFavorite)); | ||
}; | ||
|
||
return ( | ||
<button disabled={isFavorite == null} onClick={onClick}> | ||
{isFavorite == null | ||
? '…' | ||
: isFavorite | ||
? 'Remove Favorite' | ||
: 'Add Favorite'} | ||
</button> | ||
); | ||
} |
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 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,27 @@ | ||
import { relative } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { renderToString } from 'react-dom/server'; | ||
|
||
export async function load(url, context, defaultLoad) { | ||
const result = await defaultLoad(url, context, defaultLoad); | ||
|
||
if (result.format === 'module' && !url.includes('?original')) { | ||
const code = result.source.toString(); | ||
|
||
if (/['"]use client['"]/.test(code)) { | ||
const source = ` | ||
export default { | ||
$$typeof: Symbol.for('react.client.reference'), | ||
name: 'default', | ||
filename: ${JSON.stringify( | ||
relative(import.meta.dirname, fileURLToPath(url)) | ||
)}, | ||
} | ||
`; | ||
|
||
return { source, format: 'module' }; | ||
} | ||
} | ||
|
||
return result; | ||
} |
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
Oops, something went wrong.