Currently, JSON output types need to use class-based components if they want to use a content source. useContent won't work.
This is due to two restrictions on fusion engine:
1. To import from 'fusion:content', you need to be in a JSX context.
2. You can't use JSX on JSON output type, as it breaks the JSON format and tries to output an XML format.
The first might just be a webpack thing, so possibly easy to fix
Hi JP,
useContent relies on React Context internally when it is bundled via Webpack. It calls
useContext(Fusion.contexts.app)to get the content fetching machinery. That context only exists when the JSX engine renders a full React tree. JSON output types run as plain JS functions, no React tree, so hooks have nothing to pull from.But this isn't a functional gap. The JS engine passes context through props directly, and the Consumer HOC exposes it as
this.getContent(). Same capability, different API:The limitation is ergonomics. I agree, class components feel dated compared to hooks.
Fatih, can you elaborate on your comment? What do you mean by "but should consistently support useContent for feature-level content consumption". An example perhaps.
I'm trying to get clarification on if/how to use functional components to render JSON:
https://github.com/orgs/arcxp/discussions/79#discussioncomment-15563475
Any update on this? Or related docs?
Hi Santo, thanks for submitting this idea.
We've reviewed this with the team and confirm that JS components currently only support global content source, but should consistently support useContent for feature-level content consumption. Team will prioritize this product gap.