---
title: Diff
order: 2
---

<!-- prettier-ignore -->
````jsx

import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { ScriptDiffEditor } from '@riil-frontend/component-script-editor';
import { Button } from '@alifd/next';

const originalValue = `{
  "a": 1,
  "b": 2
}
`;
const value = `{
  "a": 1.1,
  "c": 3
}
`;

function App() {
	const [values, setValues] = useState({ value, originalValue });
	const switchValue = () => {
		setValues({
			value: values.originalValue,
			originalValue: values.value,
		});
	};
	return (
		<div style={{ height: '70vh', width: '70vw' }}>
			<div style={{ height: 40 }}>
				<Button onClick={switchValue}>交换内容</Button>
			</div>
			<div style={{ height: 'calc(100% - 40px)' }}>
				<ScriptDiffEditor language={'json'} value={values.value} originalValue={values.originalValue} />
			</div>
		</div>
	);
}

ReactDOM.render(<App />, mountNode);

````
