Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show the string with scaped values (normal new lines, quotes, etc)? #412 #18

Open
MiniSuperDev opened this issue Oct 16, 2023 · 1 comment

Comments

@MiniSuperDev
Copy link

Like this viewer, when the string values show the string with scaped values
image
Thanks

@jaywcjlove
Copy link
Member

jaywcjlove commented Oct 16, 2023

@MiniSuperDev Reference example: https://codesandbox.io/embed/intelligent-water-4qw3m3?fontsize=14&hidenavigation=1&theme=dark

import JsonView from "@uiw/react-json-view";

const object = {
  avatar: '"line"\nline2\nline2\nline2\n"line"',
  string: "Lorem ipsum dolor sit amet"
};

export default function App() {
  return (
    <div className="App">
      <JsonView value={object} keyName="root">
        <JsonView.String
          render={({ children, style, ...reset }, { type, value }) => {
            console.log("value", value, reset);
            if (type === "value") {
              return (
                <pre {...reset} style={{ ...style, paddingLeft: 43 }}>
                  {value}
                </pre>
              );
            }
          }}
        />
      </JsonView>
    </div>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants