diff --git a/package-lock.json b/package-lock.json index 957b53d..93b63a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@placekit/autocomplete-react", - "version": "2.2.2", + "version": "2.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@placekit/autocomplete-react", - "version": "2.2.2", + "version": "2.3.0", "license": "MIT", "dependencies": { "@placekit/autocomplete-js": "^2.2.1", @@ -29,8 +29,8 @@ "rollup-plugin-copy": "^3.5.0" }, "peerDependencies": { - "react": "^16 || ^17 || ^18", - "react-dom": "^16 || ^17 || ^18" + "react": "^16 || ^17 || ^18 || ^19", + "react-dom": "^16 || ^17 || ^18 || ^19" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 2c9fa5c..22bac2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@placekit/autocomplete-react", - "version": "2.2.2", + "version": "2.3.0", "author": "PlaceKit ", "description": "PlaceKit Autocomplete React library", "keywords": [ @@ -67,7 +67,7 @@ "prop-types": "^15.8.1" }, "peerDependencies": { - "react": "^16 || ^17 || ^18", - "react-dom": "^16 || ^17 || ^18" + "react": "^16 || ^17 || ^18 || ^19", + "react-dom": "^16 || ^17 || ^18 || ^19" } } diff --git a/rollup.config.js b/rollup.config.js index 4c8d369..40690cb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,7 +4,7 @@ import { babel } from '@rollup/plugin-babel'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import copy from 'rollup-plugin-copy'; -import pkg from './package.json' assert { type: 'json' }; +import pkg from './package.json' with { type: 'json' }; const banner = [ `/*! ${pkg.name} v${pkg.version}`, '© placekit.io', diff --git a/src/PlaceKit.jsx b/src/PlaceKit.jsx index affe52e..4be80b4 100644 --- a/src/PlaceKit.jsx +++ b/src/PlaceKit.jsx @@ -3,13 +3,19 @@ import React, { forwardRef, useCallback, useEffect } from 'react'; import { usePlaceKit } from './usePlaceKit'; +// default props as parameter defaults (React 19 ignores `defaultProps` on function components) +// `options` default is a module-level constant to keep a stable reference across renders +const DEFAULT_OPTIONS = {}; +const DEFAULT_PLACEHOLDER = 'Search places...'; + const PlaceKit = forwardRef( ( { apiKey, className, - geolocation, - options, + geolocation = true, + options = DEFAULT_OPTIONS, + placeholder = DEFAULT_PLACEHOLDER, onClient, onOpen, onClose, @@ -108,16 +114,17 @@ const PlaceKit = forwardRef( > Clear value - + ); }, ); +// kept for backward compatibility on React 16 to 18 (apps reading or mutating `PlaceKit.defaultProps`) PlaceKit.defaultProps = { geolocation: true, - options: {}, - placeholder: 'Search places...', + options: DEFAULT_OPTIONS, + placeholder: DEFAULT_PLACEHOLDER, }; PlaceKit.propTypes = { diff --git a/src/index.d.ts b/src/index.d.ts index 218cd6e..142bfae 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -34,6 +34,6 @@ export type PlaceKitHooks = { state: PKAState; }; -declare function PlaceKit(props: PlaceKitProps): JSX.Element; +declare function PlaceKit(props: PlaceKitProps): React.ReactElement; declare function usePlaceKit(apiKey: string, options?: PlaceKitOptions): PlaceKitHooks;