# Call onClickLink function inside Results view

**URL:** <https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [May 23, 2022, 7:10pm UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426 "2022-05-23T19:10:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Dias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_dias/32/104126_2.png) [@Gustavo\_Dias](https://discuss.elastic.co/u/Gustavo_Dias)\
**Post date:** [May 23, 2022, 7:10pm UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426/1 "2022-05-23T19:10:39Z")

</div>

I'm using [react search UI](https://www.npmjs.com/package/@elastic/react-search-ui) and I would like to call the onClickLink (or similar) function inside a view={} of the Results component. I know that it can be easely called by using resultView propertie, but I need to use the view prop because I need to customize the entire results panel, and not just the result component.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [May 23, 2022, 8:15pm UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426/2 "2022-05-23T20:15:39Z")

</div>

Hey @Gustavo_Dias,

Could you tell me why you need access to the `onClickLink` at the results level? Is the requirement just to customise the container, not the individual result?

Behind the scenes, the default result component is this [search-ui/Results.tsx at master · elastic/search-ui · GitHub](https://github.com/elastic/search-ui/blob/master/packages/react-search-ui-views/src/Results.tsx) . You can customise the container markup without needing to touch the resultView. for example, you can do this

```javascript

const CustomResultsView = ({ children }) => {
   return (
    <div className="custom-results-view">{children}</div>
   )
}

<Results view={CustomResultsView} />

```

You can also pair it with overriding the resultView prop to customise the rendering of each result. There you will get access to the `onClickLink` function for each result.

---

<div class="post-metadata">

**Author:** ![Gustavo\_Dias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_dias/32/104126_2.png) [@Gustavo\_Dias](https://discuss.elastic.co/u/Gustavo_Dias)\
**Post date:** [May 23, 2022, 10:45pm UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426/3 "2022-05-23T22:45:35Z")

</div>

Hello @joemcelroy , I want get the array of results and display the results in a table component of AntDesign (this is already working), and, for each time the user click on some result, I want to call the onClickLink function only to send analytical data to AppSearch.

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [May 24, 2022, 9:12am UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426/4 "2022-05-24T09:12:09Z")

</div>

understand. `onClickLink` uses the `trackClickThrough` action. [Actions | Elastic Documentation](https://docs.elastic.co/search-ui/api/actions#trackclickthrough)

See it in action here. [search-ui/Result.tsx at master · elastic/search-ui · GitHub](https://github.com/elastic/search-ui/blob/master/packages/react-search-ui/src/containers/Result.tsx#L23)

Advise that you make your own Results component and adding this action with using the `withSearch` HOC [Creating Components | Elastic Documentation](https://docs.elastic.co/search-ui/guides/creating-your-own-components#example-creating-a-component-for-clearing-all-filters)

---

<div class="post-metadata">

**Author:** ![Gustavo\_Dias](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gustavo_dias/32/104126_2.png) [@Gustavo\_Dias](https://discuss.elastic.co/u/Gustavo_Dias)\
**Post date:** [May 24, 2022, 3:33pm UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426/5 "2022-05-24T15:33:20Z")

</div>

It works by using trackClickThrough action. Thanks for your help @joemcelroy !!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 21, 2022, 3:33pm UTC](https://discuss.elastic.co/t/call-onclicklink-function-inside-results-view/305426/6 "2022-06-21T15:33:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
