diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index 26bde3ef..330fc03c 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -177,15 +177,7 @@ UseContextTestComponent(Map props) { ]); } -int calculateChangedBits(currentValue, nextValue) { - var result = 1 << 1; - if (nextValue['renderCount'] % 2 == 0) { - result |= 1 << 2; - } - return result; -} - -var TestNewContext = react.createContext({'renderCount': 0}, calculateChangedBits); +var TestNewContext = react.createContext({'renderCount': 0}); var newContextProviderComponent = react.registerComponent2(() => _NewContextProviderComponent()); diff --git a/lib/src/context.dart b/lib/src/context.dart index 96befecf..e57685a8 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -104,6 +104,7 @@ class Context { /// Learn more: https://reactjs.org/docs/context.html#reactcreatecontext Context createContext([ TValue? defaultValue, + @Deprecated('This has no effect in React 18, and there is no replacement for it.') int Function(TValue? currentValue, TValue? nextValue)? calculateChangedBits, ]) { final jsDefaultValue = ContextHelpers.jsifyNewContext(defaultValue); diff --git a/test/react_context_test.dart b/test/react_context_test.dart index 965eb538..e5e81b86 100644 --- a/test/react_context_test.dart +++ b/test/react_context_test.dart @@ -39,7 +39,7 @@ main() { sharedTypeTests(testTypeValue); }); - group('calculateChangeBits argument functions correctly', () { + group('calculateChangeBits argument does not throw when used (has no effect in React 18)', () { _ContextProviderWrapper? providerRef; _ContextConsumerWrapper? consumerEvenRef; _ContextConsumerWrapper? consumerOddRef; @@ -77,15 +77,14 @@ main() { }); test('on value updates', () { + // Test common behavior between React 17 (calculateChangedBits working) + // and React 18 (it having no effect). providerRef!.increment(); expect(consumerEvenRef!.latestValue, 2); - expect(consumerOddRef!.latestValue, 1); providerRef!.increment(); - expect(consumerEvenRef!.latestValue, 2); expect(consumerOddRef!.latestValue, 3); providerRef!.increment(); expect(consumerEvenRef!.latestValue, 4); - expect(consumerOddRef!.latestValue, 3); }); }); }); @@ -104,6 +103,8 @@ int calculateChangedBits(currentValue, nextValue) { return result; } + +// ignore: deprecated_member_use_from_same_package var TestCalculateChangedBitsContext = react.createContext(1, calculateChangedBits); var TestContext = react.createContext();