import React, { useContext } from 'react';
import { useDispatch } from 'react-redux';
import { GridContext } from './context';
/* !- Actions */
import { changeOrder, goToPage } from './actions';
/* !- Element */
import Connect from '../connect';
/**
* Provider Component
* Connect static component to Grid Redux.
* Update every affected changes.
*
* state = selected grid redux
*
* @example
*
*
* // =>
*
* @example children
*
*
*
*
* @example OnChange
* console.log(state.totalPage)}
* />
*/
const GridConnect = (props) =>
{
const context = useContext(GridContext);
const dispatch = useDispatch();
const id = props.id || context.grid;
return (
dispatch(changeOrder(column, id))}
onChangePage={nextPage => dispatch(goToPage(nextPage, id))}
onClickCell={props.onClick || (props.children ? props.children.props.onClickCell : undefined)}
{...props}
/>
);
};
export default GridConnect;