Function RelationDefinitionListContextProvider

  • Context providing consumers the current relation definition list.

    Components for editing relations can become quite complex spanning over several React components. Use this provider as the root of your custom input to prevent prop drilling on your React components.

    Parameters

    • props: PropsWithChildren<RelationDefinitionListContextType>

      Context values as defined in EntityContextType

    Returns Element

    Remarks

    This context provides a list of relation definitions. This is useful when your custom component must handle every object/subject combinations for a single relation type.

    Example

    Here is an example of a context containing the relation definitions for all target entity types from the point of view of the current entity.

    function CustomRelationInput(name: string) {
    // Make sure to wrap your form with <EntityContextProvider/>
    const entitySchema = useEntitySchema()
    // Check if we are editing the relation from the subject or object point of view
    const role = getRoleFromRelationType(name)
    // Retrieve the list of all relations from our point of view
    const relations = entitySchema.matchRelationDefinitions({
    [role]: entitySchema.type,
    type: relationType,
    })
    return (
    <RelationDefinitionListContextProvider
    relationDefinitionList={relations}
    role={role}>
    <MyCustomInputContent />
    <RelationDefinitionListContextProvider/>
    )
    }

Generated using TypeDoc