Posted 14 September 2017, 11:39 am EST
I’ve found a problem using the Wijmo 5 Flexgrid within a react project. Specifically, any components (and their children) that are rendered within a flexgrid cell are unable to access react context.
The following article has a very good explanation of how react context works.
ref: the-land-of-undocumented-react-js-the-context
I’m using an item formatter to create a react component within a flexgrid. Here’s an example in LiveScript:
# ID Column if panel.columns[c].name == \id # Get the unformatted cell data cell-data = parse-int(flex.get-cell-data(r,c, false)) render-data = React.render-to-static-markup (create CellWrapper, router:@context.router, cell-data: cell-data) if cell-data != render-data cell.innerHTML = render-data
Note that I’m passing through router as one of the parameters. This is a workaround for the context issue. I’m picking up router from context while I’m above the flexgrid and then placing the value back in context below (within the cell) the flexgrid…
module.exports = React.create-class do display-name: 'Cell Wrapper' prop-types: router: React.PropTypes.func.is-required cell-data: React.PropTypes.number.is-required # Make router visible to children as context child-context-types: router: React.PropTypes.func.is-required # Called whenever state or props changes get-child-context: -> do router: @props.router render: -> ...
As you can see, there’s quite a bit of additional code required (child-context-types, get-child-context and passing the values as props) just to be able to make a single context value available to any react components that are children of the flexgrid.
IMO, this should be handled transparently by the flexgrid with app context accessible to flexgrid children without any extra code.