Skip to content

Commit

Permalink
docs: add parcel guide
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Jan 3, 2024
1 parent 999b321 commit 1533a20
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions packages/docs/docs/frameworks/parcel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: Parcel
---

# Integrating Consent Manager with Parcel

This guide explains how to incorporate Consent Manager into a React application using Parcel. The process is quite similar to integrating with Create React App, focusing on setting up and configuring the Consent Manager efficiently.

## Example

For a hands-on example, check out our [example repository](https://github.com/hashbite/consent-manager-examples/tree/main/parcel) which contains a tested implementation.

## Installation

First, install the necessary packages:

```bash
npm install @consent-manager/core @consent-manager/interface-default use-persisted-state
```

## Setting Up the Consent Manager

### Step 1: Create Configuration File

Create a file named `consent-manager.js` in your project. This file will configure and export the `ConsentManagerWrapper` component. Here's the code for this file:

```javascript
import React from 'react'
import { ConsentManagerDefaultInterface } from '@consent-manager/interface-default'
import '@consent-manager/interface-default/dist/default.min.css'
import createPersistedState from 'use-persisted-state'

// Store consent information in localStorage
const useConsentStateStore = createPersistedState('consent-manager')

// Define your configuration here
const config = {
// ... your configuration options ...
}

export const ConsentManagerWrapper = ({ children }) => {
const storage = useConsentStateStore()

return (
<ConsentManagerDefaultInterface store={storage} config={config}>
{children}
</ConsentManagerDefaultInterface>
)
}
```

This configuration file sets up the core functionality of the Consent Manager, including storing user consent decisions.

### Step 2: Wrap Your Application

In your Parcel `index.js` file, import and utilize the `ConsentManagerWrapper` to wrap your entire application:

```javascript
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import { ConsentManagerWrapper } from './consent-manager'

const RootApp = () => {
return (
<ConsentManagerWrapper>
<App />
</ConsentManagerWrapper>
)
}

ReactDOM.render(<RootApp />, document.getElementById('root'))
```
1 change: 1 addition & 0 deletions packages/docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'frameworks/create-react-app',
'frameworks/gatsby',
'frameworks/nextjs',
'frameworks/parcel',
],
Core: [
'core/consent-manager',
Expand Down

0 comments on commit 1533a20

Please sign in to comment.