Repository navigation
Release v22.146.0
React components can now ask which module, feature and slice they are rendered in, resolved from the commands and queries in use, the slice folder they live in, or an explicit override, without passing anything down as props.
Added
useSliceContext()in@cratis/arc.react/slicesreturns theSliceLocationa component is rendered in, orSliceLocation.emptywhen nothing is known. See Slice context. (#3534)<Slice>overrides the location for everything rendered within it, fromlocation,module,featureorslice; without a location it is a boundary that keeps the commands and queries used within it from affecting the components outside it.<Arc>provides a root slice scope, anduseCommand,useQuery,useQueryWithPaging,useObservableQuery,useObservableQueryWithPaging,useChangeStreamand the suspense query hooks register the slice location of their proxy on the nearest scope while mounted. When several slices are in use, the scope keeps the parts they agree on.withViewModelin@cratis/arc.react.mvvmregisters the slice locations of the commands and queries resolved for the view model.useRegisterSliceLocation(location)for custom hooks that work with commands or queries without the Arc hooks, andwithSliceLocation(component, location)to render a component within a scope for its slice folder.SliceLocationPluginin the new@cratis/arc.vite/slicesentry point wraps exported components in slice folders so they render within a scope for their folder, withroots,segmentsToSkip,include,excludeandimportFromoptions. It keeps component names, refs,memoand React Fast Refresh working. See Resolve from slice folders at build time.SliceLocationin@cratis/arc/reflectiongainsisEmptyandequals, and is re-exported from@cratis/arc.react/slices.