A minimal, modern react binding focusing on ease-of-use
Features are being added and tested as I need them for work.
Hooks believed to work correctly (including variants)
useStateuseReduceruseContextuseRefuseEffectuseLayoutEffect
For a long time, the only way to do react was with class components. Libraries to make this easier popped up and we all ended up writing code with them. It is often verbose and difficult to reason about, but it works.
React 1.4 introduced stateless function components, a simpler way to build simple components. They are basically stateless functions taking a set of props and returning a React Element. The lucky users whose libraries supported stateless function components gained a simple model for building and reasoning about simple React components.
React 16.8 introduced 'hooks', turbocharging function components and making them equivalent in power to class components. Hooks are side effecting functions that can be used within a function component in order to tap into the extra facilities provided by the React library.
Hooks are IMHO a breakthrough feature. They're simple to reason about and they're low on boilerplate. They make React programming much more fun and productive and I never want to touch a class component again.
Reactix is a modern, Hooks-first React library focusing on simplicity and ease-of-use.
If you wish to use this library with other react libraries, you will
need to write a little glue. The minimum you can sanely get away with
is a typed wrapper over unsafeCoerce between Element and whatever your
other library's element type is.
If you already use purescript-react-basic, you may prefer
purescript-react-basic-hooks,
a similar library implemented on top of purescript-react-basic.
Not in any particular order
- Safe DOM props:
- Make sure each element only takes the correct props
- Refs
- Test forwardRef
- Context
- Test consumer (we only test useContext right now)
- Misc hooks
- Test useEffect/useLayoutEffect are fired at the correct stage
- Test useEffectOnce/useLayoutEffectOnce are fired once
- Test useMemo/useCallback
- Test useImperativeHandle
- Test useDebugValue
- Test React.isValid
- Move to
Affinstead ofEffect
New:
useEffectOnce(+ layout and prime variants) - effects which run once at component mount and cleanup once at component dismount.unsafeUseEffect,unsafeUseLayoutEffect,unsafeUseMemo,unsafeUseCallback,unsafeUseImperativeHandle- unsafe hook variants where you pass an array-like object of memo values without any help from the type system to assert such likeness to an array.
New:
useEffectFn{1-5}(+ layout and prime variants) - variants taking functions from memo values to effect, to better aid code reuse
Breaking:
useStatenow takes a (pure)Unit -> sinitialiseruseState's setter function now takes a pure fnstate -> state. To get back the old behaviour of setting a value without regard to its existing value, useconst.useReducernow takes a (pure)i -> sinitialiseruseEffect,useLayoutEffectand their numbered variants no longer take a redundant dummy unit value to delay computation.
New:
- 'Magic' DOM Props. Each takes a record of props which will be transformed
aria- prop names will be prefixed witharia-data- prop names will be prefixed withdata-on- prop names will be prefixed withon, values will bemkEffectFn1'd
Example:
import Reactix as R
import Reactix.DOM.HTML (div, text)
import DOM.Simple.Console (log)
ex :: R.Element
ex =
div
{ aria: {label: "example"}
, data: {thing: Just 1}
, on: {click: \_ -> log "Hello World"}
}
[ text "Hello World" ]Bug Fixes:
R.DOM.HTML- more or less everything was broken since we moved outcreateDOMElement
Newly supported hooks and variants:
R.Hooks.useReducerR.Hooks.useReducer'(useReducerwith a constant initial value)R.Hooks.useContextR.Hooks.useState'(useStatewith a constant initial value)R.Hooks.useEffect[1-5]'(useEffectwith no cleanup function)R.Hooks.useLayoutEffect[1-5]'(useLayoutEffectwith no cleanup function)
Newly supported functions:
R.React.createContext- create aContextwith a default valueR.React.provideContext- provide aContexta value to some childrenR.React.provider- get aProviderfor aContextR.React.consumer- get aConsumerfor aContextR.Hooks.nothing- an empty cleanup functionR.Hooks.thenNothing- make an effect function return an empty cleanup function
Changes:
R.createDOMElementis now how you create DOM elements, we removed theR.IsComponentinstance forString
Bug Fixes:
R.React.renderwas broken because the tests don't use it and neither does the main consumer of this project where it gets put through its paces
Misc:
- First attempts at all remaining hook functions have been written and not tested. Don't be surprised if they don't work.
- Remove foreign javascript file for
R.Hooksin favour offfi-simple
- Make SyntheticEvent parameterised by a native event
- Add a, li, nav, ul tags to R.DOM.Raw
- Add
R.Hooks.useRef
- First numbered release
- Made
useState,useEffectanduseLayoutEffecttake dummyUnits to delay execution until the appropriate time
Supported Hooks:
useStateuseEffect[1-5]?useLayoutEffect[1-5]?
Notable changes:
- Major refactor to use ffi-simple.
- Nicolas Pouillard, for the discussions that continue to shape the design of reactix.
- The rest of the gargantext team, for their enthusiasm both for reactix and for replacing thermite.
Copyright (c) 2018 James Laver
This software is free and open source software licensed under the terms of the Mozilla Public License (MPL) 2.0