I am using react + typescript to write a web page how to formmatted and highlight json in InputTextArea
You can use a library like react-json-view to format and highlight JSON in an Input.TextArea component. Here's an example:
import React from 'react';
import ReactJson from 'react-json-view';
import { Input } from 'antd';
const JsonInput = () => {
const [jsonValue, setJsonValue] = React.useState('');
const handleOnChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
setJsonValue(event.target.value);
};
return (
<>
<Input.TextArea rows={6} value={jsonValue} onChange={handleOnChange} />
<ReactJson src={jsonValue} theme="monokai" />
</>
);
};
export default JsonInput;
In this example, we're using the react-json-view library to display the formatted and highlighted JSON below the Input.TextArea. We're also using the useState hook to store the value of the JSON input and update it when the user types in the Input.TextArea. Finally, we're passing the value of jsonValue to the src prop of the ReactJson component to display the formatted JSON.
原文地址: http://www.cveoy.top/t/topic/bAp9 著作权归作者所有。请勿转载和采集!