Closed manuelkoch98 closed 9 months ago
@manuelkoch98 You can handle the data into a URL object, and it will automatically become a URL connection display
Ok thanks for the quick feedback :) But you don't happen to have a script lying around that checks if there is a valid URL in the object and then directly makes a link out of it, but the type is a string?
@manuelkoch98 https://codesandbox.io/p/sandbox/nostalgic-faraday-q8h2zk?file=%2Fsrc%2FApp.js%3A19%2C32&utm_source=dotnew
import JsonView from "@uiw/react-json-view";
const example = {
string: new URL("https://wangchujiang.com/"),
};
const example2 = {
string: "https://wangchujiang.com/",
};
export default function App() {
return (
<div>
<JsonView value={example} />
<JsonView value={example2}>
<JsonView.String
render={({ children, ...reset }, { type, value, keyName }) => {
const isURL = /^https?:\/\/.*$/i.test(value);
if (type === "type" && isURL) {
return <span>URL - </span>;
}
if (type === "value" && isURL) {
return <a href={value}>{value}</a>;
}
}}
/>
</JsonView>
</div>
);
}
Thank you very much :)
Is it possible to display strings in JSON as a link?