Skip to content

Commit 07837b1

Browse files
feat: add README.md with installation and usage instructions
1 parent bbef788 commit 07837b1

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

README.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# React Capture Events
2+
3+
<div align="center"> <img src="https://hebbkx1anhila5yf.public.blob.vercel-storage.com/react-capture-events-hPdo0AepAc4kCSiALhSoJOk17E138v.svg" alt="React Capture Events Logo" width="200" height="200"> </div>
4+
5+
A React library to capture and display events in a user-friendly interface. This library provides components to log, view, and manage events in your React application.
6+
7+
## 🚀 Features
8+
9+
- Capture and display events in real-time
10+
- Switch between individual event view and table view
11+
- Clear all captured events
12+
- Responsive and interactive UI
13+
14+
## 📦 Installation
15+
16+
Install the library using npm:
17+
18+
```bash
19+
npm install react-capture-events
20+
```
21+
22+
or yarn:
23+
24+
```bash
25+
yarn add react-capture-events
26+
```
27+
28+
## 🛠 Usage
29+
30+
### Basic Setup
31+
32+
1. **Register the Service Worker**
33+
34+
Register the service worker to enable event capturing:
35+
36+
```jsx
37+
import { registerServiceWorker } from 'react-capture-events'
38+
39+
registerServiceWorker()
40+
```
41+
42+
2. **Wrap Your Application with the Provider**
43+
44+
Wrap your application with the CaptureEventProvider to provide context for capturing events:
45+
46+
```jsx
47+
import React from 'react'
48+
import ReactDOM from 'react-dom'
49+
import { CaptureEventProvider } from 'react-capture-events'
50+
import App from './App'
51+
52+
ReactDOM.render(
53+
<CaptureEventProvider>
54+
<App />
55+
</CaptureEventProvider>,
56+
document.getElementById('root'),
57+
)
58+
```
59+
60+
3. **Use the CapturedEventsList Component**
61+
62+
Add the CapturedEventsList component to your application to display the captured events:
63+
64+
```jsx
65+
import React from 'react'
66+
import { CapturedEventsList } from 'react-capture-events'
67+
68+
const App = () => (
69+
<div>
70+
<h1>My Application</h1>
71+
<CapturedEventsList />
72+
</div>
73+
)
74+
75+
export default App
76+
```
77+
78+
## 📝 Capturing Events
79+
80+
To capture events, send messages to the service worker:
81+
82+
```javascript
83+
navigator.serviceWorker.controller.postMessage({
84+
type: 'LOG_EVENT',
85+
eventName: 'MyEvent',
86+
eventData: { key: 'value' },
87+
})
88+
```
89+
90+
## 🗑 Clearing Events
91+
92+
To clear all captured events, send a `CLEAR_EVENTS` message to the service worker:
93+
94+
```javascript
95+
navigator.serviceWorker.controller.postMessage({
96+
type: 'CLEAR_EVENTS',
97+
})
98+
```
99+
100+
## 📚 Examples
101+
102+
### Basic Example
103+
104+
```jsx
105+
import React from 'react'
106+
import { CaptureEventProvider, CapturedEventsList } from 'react-capture-events'
107+
108+
function App() {
109+
return (
110+
<CaptureEventProvider>
111+
<div>
112+
<h1>Event Capture Example</h1>
113+
<CapturedEventsList />
114+
</div>
115+
</CaptureEventProvider>
116+
)
117+
}
118+
119+
export default App
120+
```
121+
122+
### Advanced Example
123+
124+
```jsx
125+
import React, { useEffect } from 'react'
126+
import {
127+
CaptureEventProvider,
128+
CapturedEventsList,
129+
captureEvent,
130+
} from 'react-capture-events'
131+
132+
function App() {
133+
useEffect(() => {
134+
// Simulate capturing an event
135+
captureEvent({ type: 'click', message: 'Button clicked' })
136+
}, [])
137+
138+
return (
139+
<CaptureEventProvider>
140+
<div>
141+
<h1>Advanced Event Capture Example</h1>
142+
<button
143+
onClick={() =>
144+
captureEvent({ type: 'click', message: 'Button clicked' })
145+
}
146+
>
147+
Click Me
148+
</button>
149+
<CapturedEventsList />
150+
</div>
151+
</CaptureEventProvider>
152+
)
153+
}
154+
155+
export default App
156+
```
157+
158+
## 📄 License
159+
160+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
161+
162+
---

0 commit comments

Comments
 (0)