DeloitteAU / react-habitat

⚛️ 🛅 A React DOM Bootstrapper designed to harmonise a hybrid 'CMS + React' application.
Other
262 stars 42 forks source link

Passing an array of objects as a prop #11

Closed nonewcode closed 7 years ago

nonewcode commented 7 years ago

When i pass down [{}]. It works

When i pass down [{ id: 1 }]. It does not work.

What i've found is that you can pass down [{"1":1}] and that does work.

Is this intended?

jennasalau commented 7 years ago

Hey Josh,

Thanks for taking the time to raise the issue.

Currently by design the framework will only parse valid JSON in prop attributes. If you want to use native javascript object syntax you may be better off using the data-r-prop.

The reason for this is most backend languages/systems are happy to convert data to JSON to populate the attributes.

In terms of resolving this issue.

I'm more than happy to investigate supporting native syntax if you can help me come up with a use case for it. I'm initially reluctant though as we would have to use eval which is usually viewed as an anti-pattern and raises security issues.

Did you find the docs confusing setting properties? Perhaps we can make changes to the docs so its more clear of whats expected?

Thanks Jenna