# Query a Datasource Directly from Panel Plugin React Code

**URL:** <https://community.grafana.com/t/query-a-datasource-directly-from-panel-plugin-react-code/41293>\
**Category:** Grafana Plugin Development\
**Created:** [January 5, 2021, 11:35am UTC](https://community.grafana.com/t/query-a-datasource-directly-from-panel-plugin-react-code/41293 "2021-01-05T11:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanvalentini](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@ivanvalentini](https://community.grafana.com/u/ivanvalentini)\
**Post date:** [January 5, 2021, 11:35am UTC](https://community.grafana.com/t/query-a-datasource-directly-from-panel-plugin-react-code/41293/1 "2021-01-05T11:35:34Z")

</div>

Hello,  
I’m developing a Panel Plugin and I need to make some real-time generated queries directly from the code. Is there a way to accomplish that?  
I know there is a way in Angular but I can’t figure out how to do that in React.  
Thanks.

---

<div class="post-metadata">

**Author:** ![marcusolsson](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/marcusolsson/32/7922_2.png) [@marcusolsson](https://community.grafana.com/u/marcusolsson)\
**Post date:** [January 18, 2021, 4:29pm UTC](https://community.grafana.com/t/query-a-datasource-directly-from-panel-plugin-react-code/41293/2 "2021-01-18T16:29:52Z")

</div>

This answer suggests that you can access the data source instance using the getDatasourceSrv:

> [@Accessing Datasource from Panel](https://community.grafana.com/t/accessing-datasource-from-panel/34772/2):
>
> This is the way I am doing things with function components in v6 - there may a better way though. import React, { useState, useEffect } from 'react'; import { PanelProps } from '@grafana/data'; import { getDataSourceSrv } from '@grafana/runtime'; import { Datasource } from './types'; ... const MyPanel: React.FC\<PanelProps\> = props =\> { const [datasource, setDatasource] = useState\<Datasource\>(); ... // Setting the datasource in state - will pass down to child components in props if nee…

Would that work for your use case?

---

<div class="post-metadata">

**Author:** ![giacomosegala](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@giacomosegala](https://community.grafana.com/u/giacomosegala)\
**Post date:** [March 7, 2021, 7:28pm UTC](https://community.grafana.com/t/query-a-datasource-directly-from-panel-plugin-react-code/41293/3 "2021-03-07T19:28:21Z")

</div>

Hello Marcus,  
I’m interested in this question. It’s clear how to get the Datasource but not how to execute a query on a datasource in React, which I think was the key point of the question. More in detail, I have the need to execute a SELECT query on a MySql datasource but it’s no so clear how to do it. I found there’s a query method given by DataSource Api, but, as I said, it’s not so clear how to use it and I was not able to find any example about it.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![davidkramer12](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/davidkramer12/32/39237_2.png) [@davidkramer12](https://community.grafana.com/u/davidkramer12)\
**Post date:** [November 13, 2023, 8:48am UTC](https://community.grafana.com/t/query-a-datasource-directly-from-panel-plugin-react-code/41293/4 "2023-11-13T08:48:34Z")

</div>

Did you found solution? How to make a query ?
