At a glance, the benefits of refactoring into a completely headless component include:
fully decoupled logic + presentation layer
easier to develop new features
flexible, modular design
allows for a well defined & documented API
This approach would allow for a great deal of flexibility when creating the view/presentation layer for certain features as opposed to being locked in to a predefined layout, style, etc. The increased modularity should pave the way for a better and more productive development process. Thanks to the flexible, view agnostic design proposed here, developers would be free to apply their own styling, branding, etc.
Moving to a React Hooks based component has its own advantages as well. Exposing a custom hook could provide a lot of flexibility when it comes to working with the package. Moving to hooks would require us to specify in our docs that the React versions we support are 16.8 and up. A very reasonable compromise in my opinion.
Note that you are no longer tied to prerendered elements for features such as taking screenshots. Nor will you have to play with refs to get around that limitation.
We simply expose several useful methods that you can get access to via using the useViewer custom hook that we provide. You just pick what you need, use the destructuring syntax to get access to it and use it wherever and in whichever way you like.
There are plans to provide convenience wrapper components as well. For instance, an <XKTViewer /> component would be merely one further layer of abstraction over of what's been shown above; instead of specifying the loader plugin yourself, it would already have the XKTLoaderPlugin plugged in by default.
You would, of course, be free to choose between using the custom hook and the wrapper components as per your needs.
A rough development roadmap:
[ ] Port existing features over
[ ] Add new features; expand, supercharge existing ones
At a glance, the benefits of refactoring into a completely headless component include:
This approach would allow for a great deal of flexibility when creating the view/presentation layer for certain features as opposed to being locked in to a predefined layout, style, etc. The increased modularity should pave the way for a better and more productive development process. Thanks to the flexible, view agnostic design proposed here, developers would be free to apply their own styling, branding, etc.
Moving to a React Hooks based component has its own advantages as well. Exposing a custom hook could provide a lot of flexibility when it comes to working with the package. Moving to hooks would require us to specify in our docs that the React versions we support are 16.8 and up. A very reasonable compromise in my opinion.
Work has already commenced on these enhancements, see this feature branch.
An example usage of the new hooks based component might look something like this:
Note that you are no longer tied to prerendered elements for features such as taking screenshots. Nor will you have to play with refs to get around that limitation.
We simply expose several useful methods that you can get access to via using the useViewer custom hook that we provide. You just pick what you need, use the destructuring syntax to get access to it and use it wherever and in whichever way you like.
There are plans to provide convenience wrapper components as well. For instance, an
<XKTViewer />
component would be merely one further layer of abstraction over of what's been shown above; instead of specifying the loader plugin yourself, it would already have theXKTLoaderPlugin
plugged in by default.You would, of course, be free to choose between using the custom hook and the wrapper components as per your needs.
A rough development roadmap:
Ideas and suggestions are always welcome.