Like what we’re doing? Star us on GitHub!

Replacing useMemo with useState?

Mng
2 months ago
5

Currently, when I try to set a custom elements or leaves in the richText, I get

Cannot find a descendant at path

error which causes because useMemo is reevaluated on reloads so we might need to use useState instead?


https://github.com/payloadcms/payload/blob/master/src/admin/components/forms/field-types/RichText/RichText.tsx#L155

Related issue:

https://github.com/ianstormtaylor/slate/issues/4081


@Jarrod any thoughts?

  • jmikrut
    Payload Team
    last month

    This is probably due to your implementation, and you might be attempting to use an improper path or location



    that error is common when you try to update a node's properties (or similar) but the path that you're trying to do that against is not valid



    we do this often within Slate, all over the place in fact - so it's not something that is related to our use of

    useMemo

    vs.

    useState
  • Mng
    4 weeks ago

    @jmikrut hmm, all i wanted to do is overriding the elements in the richText so thats what i did


    <RichText name="test" label="Test" admin={{elements:['h1', 'h2']}}/>

    then i got the error i mentioned but worked fine after i replaced useMemo with useState

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More