From b350b78f6450cb7e1dbea7516f757f2b501eb2ce Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 20 Mar 2022 15:15:04 -0500 Subject: [PATCH] fix: URI not required --- .../src/controllers/entity/component.jsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/entity-persea/src/controllers/entity/component.jsx b/packages/entity-persea/src/controllers/entity/component.jsx index c45ab82..73cf6e5 100644 --- a/packages/entity-persea/src/controllers/entity/component.jsx +++ b/packages/entity-persea/src/controllers/entity/component.jsx @@ -27,13 +27,17 @@ const EntityComponent = ({ const flecks = useFlecks(); const {Entity, EntityList} = flecks.get('$avocado/resource.resources'); const [entity, setEntity] = useState(); + const dep = uri ? join(uri, path) : path; useEffect(() => { setEntity(); const loadEntity = async () => { - const entity = await Entity.load({ + const json = { ...resource, - uri, - }); + }; + if (uri) { + json.uri = uri; + } + const entity = await Entity.load(json); entity.list = new EntityList(); setEntity(entity); }; @@ -45,7 +49,7 @@ const EntityComponent = ({ setEntity(); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, [Entity, join(uri, path)]); + }, [Entity, dep]); useEffect(() => { const load = async () => { await entity?.load(resource); @@ -83,6 +87,7 @@ const EntityComponent = ({ EntityComponent.defaultProps = { path: '/', + uri: null, }; EntityComponent.displayName = 'EntityComponent'; @@ -92,7 +97,7 @@ EntityComponent.propTypes = { resource: PropTypes.shape({ traits: PropTypes.shape({}), }).isRequired, - uri: PropTypes.string.isRequired, + uri: PropTypes.string, }; export default EntityComponent;