Installation
bash
npx axis-cli add diff-viewer --agenticInteractive Demo
counter.tsx+13-5
| 1 | - | import { useState } from 'react' | |
| 1 | + | import { useState, useCallback } from 'react' | |
| 2 | 2 | ||
| 3 | - | function Counter() { | |
| 4 | - | const [count, setCount] = useState(0) | |
| 3 | + | interface CounterProps { | |
| 4 | + | initialValue?: number | |
| 5 | + | } | |
| 5 | 6 | ||
| 7 | + | function Counter({ initialValue = 0 }: CounterProps) { | |
| 8 | + | const [count, setCount] = useState(initialValue) | |
| 9 | + | ||
| 10 | + | const increment = useCallback(() => { | |
| 11 | + | setCount(prev => prev + 1) | |
| 12 | + | }, []) | |
| 13 | + | ||
| 6 | 14 | return ( | |
| 7 | - | <div> | |
| 15 | + | <div className="counter"> | |
| 8 | 16 | <p>Count: {count}</p> | |
| 9 | - | <button onClick={() => setCount(count + 1)}> | |
| 17 | + | <button onClick={increment}> | |
| 10 | 18 | Increment | |
| 11 | 19 | </button> | |
| 12 | 20 | </div> | |
| 13 | 21 | ) | |
| 14 | 22 | } |
View Modes
Unified
example.ts+2-1
| 1 | 1 | const a = 1 | |
| 2 | - | const b = 2 | |
| 2 | + | const b = 3 | |
| 3 | + | const c = 4 |
Split
example.ts+2-1
Before
| 1 | const a = 1 |
| 2 | const b = 2 |
After
| 1 | const a = 1 |
| 2 | const b = 3 |
| 3 | const c = 4 |
Usage
tsx
import { DiffViewer } from '@axis-ds/agentic-ui'
const before = `function greet(name) {
console.log("Hello, " + name)
}`
const after = `function greet(name: string) {
console.log(\`Hello, \${name}!\`)
return name
}`
export function Example() {
return (
<DiffViewer
before={before}
after={after}
filename="greet.ts"
viewMode="unified"
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
beforeRequired | string | - | 변경 전 코드 |
afterRequired | string | - | 변경 후 코드 |
filename | string | - | 파일 이름 |
viewMode | "unified" | "split" | "unified" | 뷰 모드 |
className | string | - | 추가 CSS 클래스 |
beforeRequiredType:
string변경 전 코드
afterRequiredType:
string변경 후 코드
filenameType:
stringDefault:
-파일 이름
viewModeType:
"unified" | "split"Default:
"unified"뷰 모드
classNameType:
stringDefault:
-추가 CSS 클래스