Ideas for Arc XP

Allow useContent in JSON output type

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

  • Santo Pfingsten
  • Jul 25 2023
  • Future consideration
  • Attach files
  • Admin
    Fatih Yildiz commented
    23 Mar 20:33

    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:

    import Consumer from 'fusion:consumer';

    class MyJsonOutputType extends Consumer(React.Component) {
    render() {
    const { cached } = this.getContent({ source: 'my-content-source', query: { id: this.props.id }, });
    return JSON.stringify({ data: cached });
    }
    }

    export default MyJsonOutputType;

    The limitation is ergonomics. I agree, class components feel dated compared to hooks.

  • JP Blanchette commented
    21 Mar 20:23

    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

  • JP Blanchette commented
    March 24, 2025 14:16

    Any update on this? Or related docs?

  • Admin
    Fatih Yildiz commented
    March 25, 2024 17:34

    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.