onExpandRow event
Problem Description
when I add the following to ReactTable onExpandRow={(index, event) => { console.log("expanded"); }} The row does not expand.
Adding an event handler stops the row from being expanded. If I remove the handler it works just fine. What am I missing?
System Information
Chrome Browser ReactTable version 5.5.0
onExpandRow is one of many props that helps with using react-table as a fully controlled component. When you pass the onExpandRow prop, it expects you to store the information it provides in your own state (or even change it in some way) and pass it back to the table in the expandedRows prop. Normally, you wouldn't want to use these two props unless you wanted to control the expandedRows state on your own, since the table does this for you automatically.
If you simply want to know if a row has been expanded, but not change the expandedRows state,
we would need to look into adding a way for that event to be fired somewhere else.
I am looking to load data for subcomponent on demand...only when it is expanded. Any suggestions on how I can do that? Tx.
subComponents aren't rendered until you click the down arrow, so you can actually do this with the subComponent's lifecycle hooks:
class MySubComponent extends React.Component {
constructor () {
super()
this.state = {
todos: null
}
}
componentWillMount () {
axios.get('https://myAwesomeApi.com/todos')
.then(todos => {
this.setState({ todos })
})
}
render () {
const {
todos
} = this.state
return (
<div>
<h3>Todos</h3>
{todos ? (
<ul>
{todos.map(todo => (
<li
key={todo.id}
>
{todo.text}
</li>
))}
</ul>
) : (
<span>Loading...</span>
)}
</div>
)
}
}
I see. Let me give that a try. Tx.
Worked like a charm. Closing issue.