xstate-form-machine
xstate common form machine using yup validations
Super quick start
npm install xstatenpm install xstate-form-machine
//validation.js; const phoneRegExp = /^[1][3-8][0-9]{9}$/; const nameShape = yup; const phoneShape = yup length11 "请输入手机号必须为11位" ; const addressShape = yup; //machine.js ;; const onSubmit = async { const id inputFields = context; const name phone address = inputFields; //todo}); const onSuccess = { //todo}; const onFail = { //todo}; const shapes = name: nameShape phone: phoneShape address: addressShape; ; /// ////useMachine const current send = ; const context = current; const inputFields inputErrors = {} } = context; <View className="container"> <InputBox inputFields=inputFields inputErrors=inputErrors onChange= { //send("ONCHANGE", {payload: {name, phone, address}}) to update inputs } /> <View className="confirmButton" onClick= { //send("SUMBIT", to submit ; } > <Text className="confirmText">"保存"</Text> </View> </View>