@rc-component/context
Advanced tools
Comparing version 1.1.0 to 1.2.0
import * as React from 'react'; | ||
/** | ||
* Get render update mark by `makeImmutable` root. | ||
* Do not deps on the return value as render times | ||
* but only use for `useMemo` or `useCallback` deps. | ||
*/ | ||
export declare function useImmutableMark(): number; | ||
/** | ||
* Wrapped Component will be marked as Immutable. | ||
@@ -4,0 +10,0 @@ * When Component parent trigger render, |
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import { supportRef } from "rc-util/es/ref"; | ||
import * as React from 'react'; | ||
var RenderContext = /*#__PURE__*/React.createContext(0); | ||
var ImmutableContext = /*#__PURE__*/React.createContext(0); | ||
/** | ||
* Get render update mark by `makeImmutable` root. | ||
* Do not deps on the return value as render times | ||
* but only use for `useMemo` or `useCallback` deps. | ||
*/ | ||
export function useImmutableMark() { | ||
return React.useContext(ImmutableContext); | ||
} | ||
/** | ||
* Wrapped Component will be marked as Immutable. | ||
@@ -20,3 +29,3 @@ * When Component parent trigger render, | ||
renderTimesRef.current += 1; | ||
return /*#__PURE__*/React.createElement(RenderContext.Provider, { | ||
return /*#__PURE__*/React.createElement(ImmutableContext.Provider, { | ||
value: renderTimesRef.current | ||
@@ -44,3 +53,3 @@ }, /*#__PURE__*/React.createElement(Component, _extends({}, props, refProps))); | ||
} : {}; | ||
React.useContext(RenderContext); | ||
useImmutableMark(); | ||
return /*#__PURE__*/React.createElement(Component, _extends({}, props, refProps)); | ||
@@ -47,0 +56,0 @@ }; |
import type { SelectorContext } from './context'; | ||
import { createContext, useContext } from './context'; | ||
import { makeImmutable, responseImmutable } from './Immutable'; | ||
export { createContext, useContext, makeImmutable, responseImmutable }; | ||
import { makeImmutable, responseImmutable, useImmutableMark } from './Immutable'; | ||
export { createContext, useContext, makeImmutable, responseImmutable, useImmutableMark }; | ||
export type { SelectorContext }; |
import { createContext, useContext } from "./context"; | ||
import { makeImmutable, responseImmutable } from "./Immutable"; | ||
export { createContext, useContext, makeImmutable, responseImmutable }; | ||
import { makeImmutable, responseImmutable, useImmutableMark } from "./Immutable"; | ||
export { createContext, useContext, makeImmutable, responseImmutable, useImmutableMark }; |
import * as React from 'react'; | ||
/** | ||
* Get render update mark by `makeImmutable` root. | ||
* Do not deps on the return value as render times | ||
* but only use for `useMemo` or `useCallback` deps. | ||
*/ | ||
export declare function useImmutableMark(): number; | ||
/** | ||
* Wrapped Component will be marked as Immutable. | ||
@@ -4,0 +10,0 @@ * When Component parent trigger render, |
@@ -12,2 +12,3 @@ "use strict"; | ||
exports.responseImmutable = responseImmutable; | ||
exports.useImmutableMark = useImmutableMark; | ||
@@ -24,4 +25,13 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var RenderContext = /*#__PURE__*/React.createContext(0); | ||
var ImmutableContext = /*#__PURE__*/React.createContext(0); | ||
/** | ||
* Get render update mark by `makeImmutable` root. | ||
* Do not deps on the return value as render times | ||
* but only use for `useMemo` or `useCallback` deps. | ||
*/ | ||
function useImmutableMark() { | ||
return React.useContext(ImmutableContext); | ||
} | ||
/** | ||
* Wrapped Component will be marked as Immutable. | ||
@@ -32,2 +42,3 @@ * When Component parent trigger render, | ||
function makeImmutable(Component) { | ||
@@ -42,3 +53,3 @@ var refAble = (0, _ref.supportRef)(Component); | ||
renderTimesRef.current += 1; | ||
return /*#__PURE__*/React.createElement(RenderContext.Provider, { | ||
return /*#__PURE__*/React.createElement(ImmutableContext.Provider, { | ||
value: renderTimesRef.current | ||
@@ -67,3 +78,3 @@ }, /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({}, props, refProps))); | ||
} : {}; | ||
React.useContext(RenderContext); | ||
useImmutableMark(); | ||
return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({}, props, refProps)); | ||
@@ -70,0 +81,0 @@ }; |
import type { SelectorContext } from './context'; | ||
import { createContext, useContext } from './context'; | ||
import { makeImmutable, responseImmutable } from './Immutable'; | ||
export { createContext, useContext, makeImmutable, responseImmutable }; | ||
import { makeImmutable, responseImmutable, useImmutableMark } from './Immutable'; | ||
export { createContext, useContext, makeImmutable, responseImmutable, useImmutableMark }; | ||
export type { SelectorContext }; |
@@ -30,2 +30,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "useImmutableMark", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Immutable.useImmutableMark; | ||
} | ||
}); | ||
@@ -32,0 +38,0 @@ var _context = require("./context"); |
{ | ||
"name": "@rc-component/context", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "React way perf context selector", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23381
424