@contember/interface 2.1.0-beta.2 → 2.1.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/interface",
3
3
  "license": "Apache-2.0",
4
- "version": "2.1.0-beta.2",
4
+ "version": "2.1.0-rc.2",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -1,14 +1,27 @@
1
- import { useEntityPersistSuccess } from '@contember/react-binding'
2
- import { RequestParameters, useRedirect } from '@contember/react-routing'
3
- import { RoutingLinkTarget } from '@contember/react-routing'
1
+ import { Component, useEntityPersistSuccess } from '@contember/react-binding'
2
+ import { RequestParameters, RoutingLinkFields, RoutingLinkTarget, useRedirect } from '@contember/react-routing'
4
3
 
5
- export const RedirectOnPersist = ({ to, parameters }: { to: RoutingLinkTarget; parameters?: RequestParameters }) => {
6
- const redirect = useRedirect()
7
- useEntityPersistSuccess((getEntity, options) => {
8
- if (options.successType !== 'justSuccess') {
9
- return
10
- }
11
- redirect(to, parameters)
12
- })
13
- return null
4
+ export interface RedirectOnPersistProps {
5
+ to: RoutingLinkTarget
6
+ parameters?: RequestParameters
14
7
  }
8
+
9
+ /**
10
+ * Redirects to the given target after a successful persist. Exposes a static
11
+ * render so the fields referenced by the routing target are registered during
12
+ * the static analysis pass, just like `Link`.
13
+ */
14
+ export const RedirectOnPersist = Component<RedirectOnPersistProps>(
15
+ ({ to, parameters }) => {
16
+ const redirect = useRedirect()
17
+ useEntityPersistSuccess((getEntity, options) => {
18
+ if (options.successType !== 'justSuccess') {
19
+ return
20
+ }
21
+ redirect(to, parameters)
22
+ })
23
+ return null
24
+ },
25
+ props => <RoutingLinkFields to={props.to} />,
26
+ 'RedirectOnPersist',
27
+ )