-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/TS36' into TS36
- Loading branch information
Showing
5 changed files
with
35 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
02e9a95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript 3.6, React 16.11.0 and back to react-bootstrap
This commit is a fast-forward merge of the feature-branch TS36 (now deleted). This branch started more than 2 months ago but got bigger than expected:
Updating to Typescript 3.5
It started updating to TS 3.6 when was released
Updating to React 16.11.0 (hooks all the way down)
Once updating package.json, I also updated to React 16.9.0 that contained loots of deprecations (1, 2, 3).
There was two possibilities, writing
UNSAFE_
everywhere maybe using the complexgetDerivedStateFromProps
andgetSnapshotBeforeUpdate
, or just move ahead and change all the components to functional components using hooks.We already move to hooks some months ago for the simple components, but this time almost every component has been migrated (except for SearchControlLoaded and very few others). The main benefit of hooks it that, since creating state (
useState
), running side-effects (useEffect
), creating instance variables (useRef
), etc... are all just function calls, we can extract reusable component behaviour into custom hooks that removes a lot of boilerplate in the components. Check this video to learn more.Another important benefit of moving to hooks is that the hierarchy of line components (LineBase, EntityBase, EntityLine, EntityCombo, EntityListBase, EntityStrip, EntityRepeater, EntityTable, ...) was using inheritance or React components, but this was conflicting with
React.d.ts
once it introducedReadOnly<T>
in state. By moving to hooks we can create a parallel hierarchy ofXXXController
classes anduseController
hoook to reuse functionality, removing the incompatibility with the officialReact.d.ts
.This means we can finally remove
Signum.React/node_modules
from the git repository and useSignum.React/package.json
to control the dependencies from the framework. It also means now there are two projects with package.json in Task Solution Explorer and you may need toyarn install
the dependencies of Signum.React when you update framework.Depending again on react-bootstrap
Signum Framework is not the only library that is having deprecation warnings after 16.9.
react-widgets
andreact-bootstrap
are also having the same problem. Fortunately they are working on it.react-widgets
has a v5 branch where they are also rewriting everything with hooks, but doesn't look ready yet.and
react-bootstrap
finally has a version (1.00-beta) that works with bootstrap 4 css, rewritten using hooks and contains Typescript definitions. So I moved forward and removed most of the components inSignum.React/Scripts/Components
and took again a dependency toreact-bootstrap
instead.This means whenever you want to use some custom UI components (Tabs, Tooltip, Popover, etc...) you can use React Bootstrap website as reference again.
How to update
Southwind has already been updated, so you can check the diff /~https://github.com/signumsoftware/southwind/compare/d0379fb16672e5b71ddb09941e207df335542eeb..6c1d949f2d764f98f9354042cc819a8a8c9d6f9d
The main steps are:
Signum.React/node_modules
and have to remove it manually and then doyarn install
there.YourApp.React.csproj
toTypeScriptToolsVersion
3.6.package.json
to the version that southwind uses.webpack.config.js
,webpack.config.dll.js
,vendor.js
andIndex.cshtml
.import { UncontrolledTabs, Tab } from '@framework/Components/Tabs';
by something like
import { Tabs, Tab } from 'react-bootstrap';
.react-bootstrap
Nav
,Navbar
, ... just check how Southwind does it.** Finally I strongly recommend to move all your custom components to functional components using Hooks. Many present and future tooks (custom hooks, snippets, migration regex) will assume your components are functional components, so I've built a tool that helps with the conversion to make the migration easier:
ReactHookConverter
GetFolder
to run it somewhere else).*) Replace the header (
export class Bla extends React.Component<BlaProps>
) to a function (export function Bla(p : BlaProps)
)*) replace method / lambda field to inner function.
*) It will replace
this.props.myProp
byp.myProp
*) Replace
this.state.myState
by justmyState
*) Move render to the button.
Note: The tool only works if the component is properly formatted.
useState
,useRef
,useEffect
or higher level hooks likeuseAPI
.What about Typescript 3.7?
With all this changes, this update of TS took longer than expected, so TS 3.7 has already been published with the awesome
?.
and??
operators.There is a
TS37
branch with the updated branch, but I won't merge till this syntax coloring issue in VS2019 is fixed.Conclusion
I am sure that all this changes will imporove UI development with react removing problems with
this
, and allowing custom hooks that make components simpler to understand, even if the change hurt at the beginning.Be brave 💪!
02e9a95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aswesome! 🥇
02e9a95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice and structured summary! Thank you very much!