Have a good griddle-react plugin example? - reactjs

The plug-in documentation states:
When adding functionality to Griddle, you’ll likely need to response to actions and update the application state. This can easily be done by adding action handling functions to your reducer object.
I am writing a plug-in to replace the default Pagination with bootstrap styled Pagination. This will need access to getNext() getPrevious() and setPage() in actions. I can clearly see how to access these from inside the Griddle package as the local plug-in does.
I am unsure how I would access these functions and state from a plug-in written in my application.
What do I need to import from Griddle? What do I need to call?

Found it. In the Story Book, the custom page size settings story accesses the selectors and actions exports to give a plugin more direct access to the internals. The other stories around it do a fair job of demonstrating how to access Griddle internals from the a plugin.

Note that in addition to directly accessing the exported selectors and actions, both are available through React Context as well, e.g. in LocalPlugin.components.TableBodyContainer. Context should expose the "best" selectors/actions for the current <Griddle /> after plugins have been applied.
Some work was started in https://github.com/GriddleGriddle/Griddle/pull/743 to make selectors more composable, but the PR has gone stale.

Related

Want to know about react & redux

What is the basic difference between react and redux? is react and redux is same? why we should use redux? Finally why it's called react-redux?
I want to know this i just confused between this two.
You must be pretty new to web development. First of all, welcome !
React and redux are pretty different beasts, but have often been used together to make state management easier in React apps.
React is a front-end web framework, it allows you to create a wide range of web apps using JSX (React's way of fusing Javascript and HTML). This is a gross oversimplification, I encourage you to read the documentation.
Redux is a state management library. With it, you can define one or many stores, containing a state (basically an object that holds any data you need), actions (methods to alter or retrieve the current value of the store) and to subscribe the state's changes at a global level. Again, the Redux documentation should have most of the answers you're looking for.
React and redux are often used together, mainly through the use of the react-redux package, since Redux offers a global, reactive state, enabling you to share data between React components anywhere in your app without having to pass props.
Now tough, you could achieve similar functionnality without Redux entirely, using React's own Hook and Context APIs. Although the logic behind these is a bit more involved, it allows for far more flexibility.

Next.js. Where to put a global provider?

I'm working with Next.js and I need to implement i18n. It requires me to add some global provider that should wrap the whole app. Also, it must receive updates from some state management (eg. Redux) to properly re-render the whole app when the active Language changes.
In the standard React app we have App.js that we put into index.js and keep all logic/providers here.
But in the case of Next, I'm not sure where to put this logic. I double-checked their documentation but I didn't find any mention about it.
Only about _app.js and _document.js but actually both don't have a possibility to be connected to Redux, etc. Actually they weren't designed for this.
I'm just curious if Next provides some official way to do it or should I just manually create some HOC as App just and wrap the whole app by myself?
Btw. I barely understand the difference between _app and _document. So I'll appreciate any clarification as well!
Please read the documentation more carefully then, you can find Keeping state when navigating pages on the second point here.
That's what redux used for.
I'm able to connect my entire app to redux and i18n from _app.js file. In my previous project, my teammates even use _document.js file to connect i18n.
As you can see from their doc, the purpose of this _app.js is to override and control the page initialization. So, you can receive updates from redux and put the changes on IntlProvider right before rendering your page.
Other solution is like what you have said, by creating some HOC to wrap your app.
The choice is yours.
You can use next-connect-redux package.
Github page
Example repo

Tabulator: React formater: need 'dispose' handler for a correct implementation

react-tabulator is a library providing an integration of Tabulator in React. Their solution to render a React component within a Tabulator formater uses this function. However, I don't think this is 100% correct, because based on the React doc on integrating React w/ plain JS, ReactDOM.unmountComponentAtNode() needs to be called on dispose in order to to some cleanup. I also communicated this to the author within a GitHub issue, and maybe he'll provide additional info.
My question: is there a hook/handler/way to receive notifications when a cell is being disposed? 1) This will allow me to call the mentioned method, so that React can do some cleanup. 2) This opens also the path towards an alternative approach, leveraging React portals.
Thank you in advance!
I have created an implementation using portals in this gist. It's a Storybook pages. I'm using semantic-ui-react in my project, so a copy/paste of the file may need adapting.
I don't know if it's OK to have thousands of portals. I.e. one per cell. Also, I didn't see any action do "dispose" a portal. I hope that disposing the DOM element where the portal was rendered suffices. Otherwise => memory leaks possible I think.

what is a generally acceptable way to structure a service layer in a reactjs project?

I'm using axios.get() to call an api endpoint in one of my components. I need the ability to encapsulate this endpoint call so I can reuse this implementation by calling it from several different components.
What is a generally acceptable way to structure this type of implementation in a React project? For example, would it be generally acceptable to group related api calls into js files in a src/services directory at the same level as src/components?
It would be acceptable to create a utils or services directory and group related API calls. However it is important to remember that with async requests you need to consider the components calling the api service utils might un-mount. This might result in warnings or errors if not handled properly. A possible way to handle this might be to only execute callback functions if component is still mounted tracked via a state variable in a useEffect hook.
A more modern react approach might be to leverage hooks and react context for data handling. You could create a DataContext with a useReducer hook to fetch or push data for example.
(see https://reactjs.org/docs/context.html)
There are many way to do this.
Redux. It's old way is that you need to use redux style.
Hooks. Starts from React 16.8 version.
I will recommend to you use hooks. It's more useful and guarantee true way.
3 years ago i lived in Redux paradigm and every time write the monkey code thinking about consistent Redux store state.
Please try this one react-async package.

How to retrieve a react element from a dom element

The question here is not about is this a good idea or not, because there is a real use-case : I'm scraping a specific website from a headless browser for an internal service and I need to extract data from react.
From an active production application, I would like to retrieve props from the root component using only "pure" JavaScript. The only thing I got is a div right now.
The constraints are:
It must be done using pure JavaScript (or using standard React lib)
I cannot add/setup react-devtools extensions or things like that
So far I could always hack into an event handler that I would trigger to manage to enter into React context but I'm looking for cleaner alternatives, any ideas?

Resources