strapi / blocks-react-renderer

A React renderer for the Strapi's Blocks rich text editor
Other
162 stars 25 forks source link

Allow to use the RootNode type #11

Closed Frost-on-Web closed 1 year ago

Frost-on-Web commented 1 year ago

If we display the RootNode type, it can be easily used into custom interfaces which are useful to define any API inputs.

What does it do?

Just display the RootNode type in order to use it to define my API input type 👍

import type { RootNode } from "@strapi/blocks-react-renderer";

export interface IStrapiAlertMessageData {
  title: string;
  message: RootNode[]; // <======= Here we go
  starting_date: string;
  ending_date: string;
}

How to test it?

import type { IStrapiAlertMessageData } from "./AlertMessageComponent";

function AlertMessageDisplayBlock({ message }: IStrapiAlertMessageData) {
  return (
      <BlocksRenderer content={message} />
  );
}

Please be kind

Hi, it is one my first PR of all time and English is not my first language so please apologize my lack of verbosity. Hoping to be helpful.

remidej commented 1 year ago

Hello @Frost-on-Web, thanks for opening the PR, and especially for explaining your need in details.

I'm not going to merge it because I'm planning on updating this package to use the types from @strapi/types, instead of defining them here in this repo.

But there are 2 ways you can get access to that type:

Via the @strapi/types package:

import type { Attribute } from '@strapi/types';

type RootNode = Attribute.BlocksValue;

Via the renderer prop:

import * as React from 'react';
import { BlocksRenderer } from '@strapi/blocks-react-renderer';

type RootNode = React.ComponentProps<typeof BlocksRenderer>['content'];

I haven't actually tried these, so apologies if there's any error. I hope this helps!

joshuaellis commented 1 year ago

@remidej we do not advise people to access types form that package.

They're always re-exported from strapi/strapi - that could be an offering, but honestly I would have had them exported from here because you're making using this package potentially dependant on using CMS packages with a strict release cycle... which imo makes having this package in its own repo, redundant.

Also a mismatch in package versions could break usr applications 🙂

Happy to meet and discuss, LMK.