Skip to content

Commit

Permalink
docs(:memo:) adding preact usage docs
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicpages committed Nov 25, 2020
1 parent d75c6c4 commit 845a268
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ Make sure you're on a supported version of React and React DOM:

```sh
npm i react@^16.9 react-dom@^16.9

# or use the latest and greatest react
npm i react react-dom
```

### Using Preact?

PCR seamlessly integrates with Preact :sunglasses:, you don't even need to include `preact/compat`!

## Basic Usage

PCR components are easy to use and require no additional setup. Use as controlled or uncontrolled, use with hooks or with classes, and pass all the props you want -- it's all forwarded to the underlying `input` element. Hungry for more? Head on over the the [doc site](https://pretty-checkbox-react.netlify.app/).
Expand Down
57 changes: 57 additions & 0 deletions docs/docs/usage/preact.md
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>;
}
```
6 changes: 5 additions & 1 deletion docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ module.exports = {
label: 'API Reference',
to: 'docs/api/checkbox/',
},
{
label: 'Alternative Technologies',
to: 'docs/api/usage/preact',
},
],
},
{
Expand All @@ -142,7 +146,7 @@ module.exports = {
copyright: `Made with \u2665 by Dennis Thompson & Docusaurus \uFF5C &copy; ${new Date().getFullYear()}`,
},
algolia: {
apiKey: process.env.ALGOLIA_KEY,
apiKey: process.env.ALGOLIA_KEY || 'abc',
indexName: 'pretty-checkbox-react',
searchParameters: {}, // Optional (if provided by Algolia)
},
Expand Down
3 changes: 3 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ module.exports = {
{
'Migration Guide': ['migration/migrating-2.x', 'migration/migrating-1.x'],
},
{
'Other Technologies': ['usage/preact'],
},
],
};

0 comments on commit 845a268

Please sign in to comment.