@dotcms/react 1.2.0-next.6 → 1.2.0-next.8

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/index.esm.js CHANGED
@@ -7580,13 +7580,19 @@ const useAISearch = ({
7580
7580
  indexName,
7581
7581
  params
7582
7582
  }) => {
7583
- var _state$response;
7583
+ var _state$response$resul, _state$response;
7584
7584
  const [state, dispatch] = useReducer(reducer, {
7585
7585
  response: null,
7586
7586
  status: {
7587
7587
  state: DotCMSEntityState.IDLE
7588
7588
  }
7589
7589
  });
7590
+ // Use ref to store params so search callback doesn't change when params change
7591
+ const paramsRef = useRef(params);
7592
+ // Keep ref updated with latest params
7593
+ useEffect(() => {
7594
+ paramsRef.current = params;
7595
+ }, [params]);
7590
7596
  const reset = useCallback(() => {
7591
7597
  dispatch({
7592
7598
  type: DotCMSEntityState.IDLE
@@ -7603,7 +7609,7 @@ const useAISearch = ({
7603
7609
  type: DotCMSEntityState.LOADING
7604
7610
  });
7605
7611
  try {
7606
- const response = await client.ai.search(prompt, indexName, Object.assign({}, params));
7612
+ const response = await client.ai.search(prompt, indexName, Object.assign({}, paramsRef.current));
7607
7613
  dispatch({
7608
7614
  type: DotCMSEntityState.SUCCESS,
7609
7615
  payload: response
@@ -7614,10 +7620,10 @@ const useAISearch = ({
7614
7620
  payload: error
7615
7621
  });
7616
7622
  }
7617
- }, [client, indexName, params]);
7623
+ }, [client, indexName]);
7618
7624
  return {
7619
7625
  response: state.response,
7620
- results: (_state$response = state.response) == null ? void 0 : _state$response.results,
7626
+ results: (_state$response$resul = (_state$response = state.response) == null ? void 0 : _state$response.results) != null ? _state$response$resul : [],
7621
7627
  status: state.status,
7622
7628
  search,
7623
7629
  reset
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/react",
3
- "version": "1.2.0-next.6",
3
+ "version": "1.2.0-next.8",
4
4
  "peerDependencies": {
5
5
  "react": ">=18",
6
6
  "react-dom": ">=18"
@@ -7,7 +7,7 @@ import { DotCMSAISearchContentletData, DotCMSAISearchParams, DotCMSAISearchRespo
7
7
  */
8
8
  export interface DotCMSAISearchValue<T extends DotCMSBasicContentlet> {
9
9
  response: DotCMSAISearchResponse<T> | null;
10
- results: DotCMSAISearchContentletData<T>[] | undefined;
10
+ results: DotCMSAISearchContentletData<T>[];
11
11
  status: DotCMSEntityStatus;
12
12
  search: (prompt: string) => Promise<void>;
13
13
  reset: () => void;