Search code examples
reactjsmaterial-table

How to call function witch returning value is datasource for Material Table?


So I have Material Table component witch get it's data from function that get's it with filter from database. Now the problem is that I have props that should re-render that table but that won't happen. I can't simple call that function when needed. I have tried using the references but it wont help or I just can't do it. Code is like:

const ajax = (params) => {
    .
    .
    .
    return {
       data: result.data
    }
}

return (<>
    <MaterialTable data={ajax}>
</>
)

Solution

  • That reference thing works fine:

    import React from 'react'
    const tableRef = React.createRef
    const App = (props) => {
      tableRef?.current.onQueryChange()
      const ajax = (params) => {
        .
        .
        .
        return data
      }
      return (MaterialTable data={ajax} tableRef={tableRef}...)
    }