Comments (5)
// similar to settings-panel
const params = [{ id: 'number', type: Number }]
const params2 = { number: 3, ... }
const [ fields, { set, submit, validate, reset } ] = useForm( params )
const { fieldName: { valid, error, touched, ref, type, validate }, ...rest } = fields
const [ { value, error, touched, ref, input }, { validate, set } ] = useField( 'name', { type: Number, validate: (value) => {} } )
from unihooks.
react-table introduces nice useTable hook approach, able to generate props for target elements. Same technique can be used here.
from unihooks.
3 aspects of useFormFIeld
.
-
Possibly unnecessary separation of
useFormField
anduseInput
: separates creation of some data from accessing - not conceptually very much different. -
useValidation
can be a part of functionality, augmentinguseInput
. (although it redefinesonChange
, which may be redundant. -
Passing input props into hook, instead of direct element is doubtful practice. It's better to focus on direct generating the UI, instead of passing props through some transforms.
from unihooks.
useValidation
is insufficient on itself: it must show error only when the input is blurred, not when focused, so it depends on input element state.
Also, we may want to validate on form submit for example, but validate requires value to check against, since it is not bound to specific input - therefore it is useful to have something that knows about "input store".
So, responding to 1, 2, 3.
- No need to separate - it can be used bot for creating and controlling, single hook returns "state" of some input element (null-ish state is allowed - it is not fully null but detached). That "virtual" state can optionally be rendered to real node.
field.validate()
is better.- No need to pass input props, pass minimal input config.
from unihooks.
The quesion is: how to use useFormField
as aspect, considering that it may create an input?
This is very similar to useStore(id, initObj)
- if id is not found, it is created..
There can therefore be useFormField(id|element, initProps)
.
Conceptually, that is similar to upsert proposal: upsert(id, update: oldValue => newValue, insert: () => initValue)
, but in case of hooks update
and insert
functions are single init
function.
More generally, resource hook creates a thread (like in erlang) of specific functionality (specific lens to look at data source).
To overcome explicit createStore
call, there must be main aspect and auxiliary aspects - main aspect creates/controls entry, aux augments behavior.
from unihooks.
Related Issues (20)
- useInput
- useCrossCall / RPC
- useOmniStorage
- References / alternatives / friends / similar HOT 5
- useEffect group (possible effects)
- useDate
- server context
- immutability for stored value
- useResource
- useQueryParam: hangs browser
- useQueryParam: default === init
- useQueryParam: null keeps value in URL
- useAction HOT 2
- 2.0 HOT 2
- useState / useEffect async HOT 1
- heresy
- useComponent / useAPI / useChannel? HOT 1
- useStorage / useChannel / useAction order checks
- `setQS('')` clears up location
- Friends
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unihooks.