-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(:memo:) adding preact usage docs
- Loading branch information
1 parent
d75c6c4
commit 845a268
Showing
4 changed files
with
72 additions
and
1 deletion.
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,57 @@ | ||
--- | ||
id: preact | ||
title: Preact | ||
--- | ||
|
||
PCR works out of the box with Preact 10 due to the simplicity of the components. Literally can't get any easier :wink:. | ||
|
||
## Install | ||
|
||
```sh | ||
npx preact-cli preactjs-templates/simple preact_app | ||
cd preact_app | ||
npm i pretty-checkbox pretty-checkbox-react | ||
``` | ||
|
||
## Usage | ||
|
||
From the `index.js` file in your Preact app: | ||
|
||
```jsx | ||
import { Checkbox, useCheckboxState } from 'pretty-checkbox-react'; | ||
import '~/pretty-checkbox'; | ||
|
||
export default function App() { | ||
const checkbox = useCheckboxState(); | ||
|
||
return ( | ||
<> | ||
<Checkbox {...checkbox}>It lives!</Checkbox> | ||
<p>Checked: {checkbox.state + ''}</p> | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
Wowza 🤯 so easy! | ||
|
||
### Usage with Hooks | ||
|
||
As per the Preact docs, we can use hooks from `preact/hooks` or from `preact/compat`: | ||
|
||
```jsx | ||
import { useRef, useEffect } from 'preact/hooks'; | ||
import { Checkbox } from 'pretty-checkbox-react'; | ||
|
||
import '~/pretty-checkbox'; | ||
|
||
export default function App() { | ||
const ref = useRef(null); | ||
|
||
useEffect(() => { | ||
console.log(ref); | ||
}, []); | ||
|
||
return <Checkbox ref={ref}>It lives!</Checkbox>; | ||
} | ||
``` |
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