From 751e2c2042cd50523b0e67e0bb9b1acdbd6437cf Mon Sep 17 00:00:00 2001 From: "DESKTOP-5V12CA1\\Regi" Date: Mon, 24 Jul 2023 18:19:43 +0200 Subject: [PATCH] input formiker --- Parts/Input.js | 102 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/Parts/Input.js b/Parts/Input.js index 3c706f8..3724889 100644 --- a/Parts/Input.js +++ b/Parts/Input.js @@ -1,47 +1,111 @@ -import React from "react" +import React from "react"; -import tw, { styled } from "twin.macro" -import "styled-components/macro" +import tw, { styled } from "twin.macro"; +import "styled-components/macro"; +import { useField as useFormikField, useFormikContext } from "formik"; + +export function useField(props){ + let getField = useFormikField; + const context = useFormikContext(); + if(!context){ + getField = (props)=>{ + return [props, null, null]; + } + } + return getField(props); +} + +export default function Input({ label, title, className, children, ...props }) { + /*name, id*/ + + const [field, meta, helpers] = useField(props); -export default function Input({ label, title, className, name, id, children, ...props }) { return (
{title && ( -
- ) + ); } -export function TextArea({ label, title, className, name, id, children, ...props }) { +export function TextArea({ + label, + title, + className, + children, + ...props +}) { + + const [field, meta, helpers] = useField(props); + return (
{title && ( -