How to use the formik.useFormikContext function in formik

To help you get started, we’ve selected a few formik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / formik_v2.x.x / flow_v0.104.x- / test_formik.js View on Github external
it('should return context with passed values', () => {
    const context = useFormikContext<{ age: number, ... }>();

    (context.values.age: number);
    // $ExpectError: check any
    (context.values.age: string);
  });
});
github chaos-mesh / chaos-mesh / ui / src / components / NewExperiment / Stepper / Target / Pod.tsx View on Github external
export default function Pod(props: StepperFormTargetProps) {
  const { errors, touched, values }: FormikCtx = useFormikContext()
  const { handleActionChange } = props

  return (
    <>
       {}} // Delay the form validation with an empty func. If don’t do this, errors will appear early
      >
        {actions.map((option: string) => (
          <menuitem value="{option.split('">
            {toTitleCase(option)}</menuitem>
github chaos-mesh / chaos-mesh / ui / src / components / NewExperiment / Stepper / Target / IO.tsx View on Github external
export default function IO(props: StepperFormTargetProps) {
  const { values, errors, touched }: FormikCtx = useFormikContext()
  const { handleActionChange } = props

  return (
    &lt;&gt;
       {}} // Delay the form validation with an empty func. If don’t do this, errors will appear early
      &gt;
        {actions.map((option: string) =&gt; (
          <menuitem value="{option}">
            {toTitleCase(option)}
          </menuitem>
github chaos-mesh / chaos-mesh / ui / src / components / NewExperiment / Stepper / Target / Time.tsx View on Github external
export default function Time() {
  const formikCtx: FormikCtx = useFormikContext()
  const { errors, touched } = formikCtx

  useEffect(() =&gt; {
    resetOtherChaos(formikCtx, 'TimeChaos', false)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

  return (
    &lt;&gt;
github chaos-mesh / chaos-mesh / ui / src / components / NewExperiment / Stepper / Target / index.tsx View on Github external
const Target: React.FC = () =&gt; {
  const classes = useStyles()

  const formikCtx = useFormikContext()
  const kind = formikCtx.values.target.kind

  const [selected, setSelected] = useState('')

  const handleActionChange = (kind: string) =&gt; (e: React.ChangeEvent) =&gt;
    resetOtherChaos(formikCtx, kind, e.target.value)

  const handleSelectTarget = (kind: ExperimentKind) =&gt; () =&gt; setSelected(kind)

  const renderBySelected = () =&gt; {
    switch (selected) {
      case 'PodChaos':
        return 
      case 'NetworkChaos':
        return 
      case 'IoChaos':
github akeneo / pim-community-dev / src / Akeneo / Connectivity / Connection / front / src / settings / pages / EditConnection.tsx View on Github external
const SaveButton = () =&gt; {
    const formik = useFormikContext();

    return (
         formik.submitForm()}
            disabled={!formik.dirty || !formik.isValid || formik.isSubmitting}
            classNames={['AknButtonList-item']}
        &gt;
            
        
    );
};
github chaos-mesh / chaos-mesh / ui / src / components / NewExperiment / Stepper / Target / Stress.tsx View on Github external
export default function Stress() {
  const formikCtx: FormikCtx = useFormikContext()
  const { values, setFieldValue } = formikCtx

  const actionRef = useRef('')
  const [action, _setAction] = useState('')
  const setAction = (newVal: string) => {
    actionRef.current = newVal
    _setAction(newVal)
  }

  useEffect(() => {
    resetOtherChaos(formikCtx, 'StressChaos', false)

    if (getIn(values, 'target.stress_chaos.stressors.cpu') === null) {
      setFieldValue('target.stress_chaos.stressors.cpu', defaultExperimentSchema.target.stress_chaos.stressors.cpu)
    }
github chaos-mesh / chaos-mesh / ui / src / components / NewExperiment / Stepper / Target / Network.tsx View on Github external
export default function Network(props: StepperFormTargetProps) {
  const { errors, touched, values, setFieldValue }: FormikCtx = useFormikContext()
  const { handleActionChange } = props

  const { namespaces } = useSelector((state: RootState) => state.experiments)

  const initTarget = () => setFieldValue('target.network_chaos.target', defaultExperimentSchema.scope)
  const initPartitionTarget = () => {
    const target = getIn(values, 'target.network_chaos.target')

    setFieldValue(
      'target.network_chaos.target',
      Object.assign(
        {
          ...defaultExperimentSchema.scope,
          mode: 'all',
        },
        target
github ewels / MegaQC / src / util / autoSave.js View on Github external
export const AutoSave = ({ debounceMs }) => {
  const formik = useFormikContext();
  const debouncedSubmit = useCallback(debounce(formik.submitForm, debounceMs), [
    debounceMs,
    formik.submitForm
  ]);

  useEffect(debouncedSubmit, [debouncedSubmit, formik.values]);

  return null;
};
export default AutoSave;
github akeneo / pim-community-dev / src / Akeneo / Connectivity / Connection / front / src / settings / pages / EditConnection.tsx View on Github external
const FormState = () =&gt; {
    const formik = useFormikContext();

    return (
        (formik.dirty &amp;&amp; (
            <div>
                <span>
                    
                </span>
            </div>
        )) ||
        null
    );
};