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 08:33pm

    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 08:23pm

    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
    24 Mar, 2025 02:16pm

    Any update on this? Or related docs?

  • Admin
    Fatih Yildiz commented
    25 Mar, 2024 05:34pm

    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.