Skip to content

Commit af04140

Browse files
committed
feat: export repl store
1 parent 8c4c169 commit af04140

File tree

5 files changed

+26
-65
lines changed

5 files changed

+26
-65
lines changed

README copy.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
# repl-react
22

3-
WIP
4-
53
A online playground for react, inspired by [vue/repl](https://github.com/vuejs/repl) and [unocss/playground](https://github.com/unocss/unocss/tree/main/packages/playground).
64

75
Thanks to the open source of [vue/repl](https://github.com/vuejs/repl) and its maintainers, this project is built to provide a similar experience for react.
86

9-
## Features
7+
# @zhangmo8/repl-react
8+
9+
React REPL as a React component.
10+
11+
## Basic Usage
1012

11-
- Code editor with syntax highlighting
12-
- Realtime preview of react components
13-
- Code snippet support
13+
```ts
14+
// vite.config.ts
15+
import { defineConfig } from 'vite'
16+
export default defineConfig({
17+
optimizeDeps: {
18+
exclude: ['@zhangmo8/repl-react'],
19+
},
20+
// ...
21+
})
22+
```
1423

15-
## How to use
24+
```javascript
25+
import { Repl } from '@zhangmo8/repl-react'
1626

17-
1. Include the script in your HTML page
27+
<Repl />
28+
```

src/components/Editor/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { ReplContext } from "@/store"
2-
import { useContext } from "react"
1+
import { useReplStore } from "@/store"
32

43
import CodeMirror from "./CodeMirror"
54

65
const EditorContainer = () => {
7-
const { state, onChangeCode } = useContext(ReplContext)
6+
const { state, onChangeCode } = useReplStore()
87
const { code = "" } = state
98

109
return (

src/components/Output/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useCallback, useContext, useEffect, useMemo, useState } from "react"
1+
import { useCallback, useEffect, useMemo, useState } from "react"
22

33
import CodeMirror from "@/components/Editor/CodeMirror"
44
import { type OutputCode, transformCode } from "@/hooks/swc"
5-
import { ReplContext } from "@/store"
5+
import { useReplStore } from "@/store"
66

77
import Preview from "./Preview"
88
import "./styles.css"
@@ -14,7 +14,7 @@ const outputTabs = [
1414
]
1515

1616
const Output = () => {
17-
const { state } = useContext(ReplContext)
17+
const { state } = useReplStore()
1818
const { code = "", showAST, showCompile } = state
1919
const [activeTab, setActiveTab] =
2020
useState<(typeof outputTabs)[number]["value"]>("preview")

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from './Repl'
1+
export * from "./Repl"
2+
export { useReplStore } from "./store"

0 commit comments

Comments
 (0)