-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to get the data by 'griddleKey'? #761
Comments
Hi, @MichaelDeBoey, I did like this (I use typescript): import { connect } from "react-redux";
export const rowDataSelector = (state, { griddleKey }) => {
return state
.get("data")
.find(r => r.get("griddleKey") === griddleKey)
.toJSON();
};
export class CustomGrid extends React.Component<Props, {}> {
...
const StandardRow = ({ Cell, griddleKey, columnIds, style, className, rowData }) => {
return (
<tr
onClick={(e) => {
// dirty hack before griddle will implement normal onRowClick
(e as any).rowData = rowData;
this.props.onRowClick(e);
}}
key={griddleKey}
style={style}
id={rowData.id}
className={className + " " + styles.tableRow}
>
{columnIds && columnIds.map(c => (
<Cell
key={`${c}-${griddleKey}`}
griddleKey={griddleKey}
columnId={c}
style={style}
className={className}
/>
))}
</tr>
);
};
const standardRowMapStateToProps = (state, props) => {
return {
rowData: rowDataSelector(state, props),
};
};
const enhancedStandardRow = connect(standardRowMapStateToProps)(StandardRow)
...
return(){
<Griddle
components={{
Row: enhancedStandardRow
}} |
You'll get better performance using the import { selectors, GriddleComponents } from 'griddle-react';
import { connect } from 'react-redux';
import mapProps from 'recompose/mapProps';
const EnhanceWithRowData = connect((state, props) => ({
rowData: selectors.rowDataSelector(state, props)
}));
const components: GriddleComponents = {
RowEnhancer: EnhanceWithRowData(
mapProps(props => ({
...props,
onClick: () => {
console.log(`Clicked Row ${props.griddleKey}`);
console.log('props', props);
},
}))
),
}; |
@dahlbyk Thanks for the help! 🙂 Unfortunately I didn't manage to make this work 😕 Uncaught TypeError: state.getIn is not a function
at Object.rowDataSelector (dataSelectors.js:299)
at actions.js:7
at Object.dispatch (index.js:11)
at dispatch (<anonymous>:2:1620)
at showDocument (index.js:200)
at onClick (index.js:65)
at HTMLUnknownElement.callCallback (react-dom.development.js:540)
at Object.invokeGuardedCallbackDev (react-dom.development.js:579)
at Object.invokeGuardedCallback (react-dom.development.js:436)
at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:450)
at executeDispatch (react-dom.development.js:834)
at executeDispatchesInOrder (react-dom.development.js:856)
at executeDispatchesAndRelease (react-dom.development.js:954)
at executeDispatchesAndReleaseTopLevel (react-dom.development.js:965)
at Array.forEach (<anonymous>)
at forEachAccumulated (react-dom.development.js:933)
at processEventQueue (react-dom.development.js:1105)
at runEventQueueInBatch (react-dom.development.js:3600)
at handleTopLevel (react-dom.development.js:3609)
at handleTopLevelImpl (react-dom.development.js:3340)
at batchedUpdates (react-dom.development.js:11066)
at batchedUpdates (react-dom.development.js:2323)
at dispatchEvent (react-dom.development.js:3414) I replecated this in a codesandbox, maybe you could point me in the right direction? When I |
@dahlbyk Doh The codesandbox is just a link to the default sandbox, will provide a new link tonight 🙂 |
@dahlbyk New codesandbox link: https://codesandbox.io/s/30qvo721x6 🙂 Just click on a row an you'll see the error I get 🙂 |
@MichaelDeBoey take a look at https://codesandbox.io/s/r50q23027o. You're using I did mess up my example slightly; const EnhanceWithRowData = utils.connect((state, props) => ({
rowData: selectors.rowDataSelector(state, props)
}));
const components = {
RowEnhancer: compose(
EnhanceWithRowData,
withHandlers({
onClick: props => () => {
console.log(`Clicked Row ${props.griddleKey}`);
console.log('props', props);
},
})
),
}; |
@dahlbyk Thanks for the example. 🙂 I was planning on extracting the I want to make my components as clean as possible and want to do all the logic in the Replacing |
If you're using Griddle, you have a dependency on
Your sandbox is using Griddle 1.9, which doesn't include #751. Try this instead: import Griddle, { utils, plugins } from 'griddle-react';
const { connect } = utils;
Ultimately you're going to keep running into the fact that there are two Redux stores, with two Here's another demo that implements support for a generic |
@dahlbyk Thanks for your help. 🙂
I know, but I meant a direct dependency. 🙂
The I would think that if you use |
You're using Griddle's Now also seems like a good time to point out that you can add Redux middleware to the Griddle store via You have lots of options, just depends how exactly you want to break things up. 😀 |
OK so back to the separate Still breaks 'cause a TypeError (like you can see in v5 of the sandbox) 😕 |
That RowEnhancer is a HOC is tripping you up. You're trying, conceptually:
You need to do this instead:
https://codesandbox.io/s/mk6nxyl9j Composing HOCs is pretty messy, thus using Recompose:
|
@dahlbyk OK thanks for the explanation, that's one step closer to the solution 🙂 I now get the following error (like you can see in v6 of the codesandbox): Actions must be plain objects. Use custom middleware for async actions. So I just added the import thunk from 'redux-thunk';
// ...
return <Griddle reduxMiddleware={[thunk]} />; |
Great! I'm going to close this, but let us know if you have any other questions. |
Thanks for all your help @dahlbyk! |
Griddle version
^1.10.0
Problem
So I'm using my own
RowEnhancer
, so I can implement my ownonClick
, like this:When I click on the row, I get the following log:
The
griddleKey
here would be useful to get al the row-data back I guess, but I can't seem to find out how this should be done. 😕Can somebody help me please?
The text was updated successfully, but these errors were encountered: