Skip to content

Pass JSON as attributes #68

@n1ru4l

Description

@n1ru4l

It would be cool if JSON values could be passed as props to the react component, similar to JSX.

E.g. <MyComponent items={[1, 2, 3, 4]} /> or <MyComponent items={{a: 1, b: 2, c: 3}} />.

const MyComponent = ({ items }) => {
  return <>{items.map(item => String(item))}</>;
};

This would be more convenient compared to the current workaround of passing stringified JSON: <MyComponent items='{"a": 1, "b": 2, "c": 3}' />.

const MyComponent = ({ items }) => {
  items = JSON.parse(items);
  return <>{items.map(item => String(item))}</>;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions