question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initialization of status

See original GitHub issue

Bug, Feature, or Question?

Bug

Current Behavior

When including a reference to this.status.property in a Formik inner component, where property is determined after handleSubmit is called, initially referencing this.status.property results in error: Cannot find property ‘property’ of undefined

Desired Behavior

Reference to this.status.property should return undefined on component initialization.

Suggested Solutions

After a few hours of digging, and looking at this CodeSandbox, the current solution is to append this.status && before this.status.property so the conjunction short-circuits to false.

Given this is a basic JS fact of how objects evaluate, it may seem like the solution is obvious, but I found the documentation regarding how status is handled a little sparse.

Maybe there could be a initializeStatus property for the Formik component which allows you to specify status on page initialization?

  • Formik Version: 0.11.11
  • React Version: 16.0
  • TypeScript Version: N/A
  • CodeSandbox Link: https://codesandbox.io/s/ppnkqv78wq
  • OS: Windows 10
  • Node Version: 9.5
  • Package Manager and Version: npm 5.6.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
prichodkocommented, Mar 1, 2018

I would recommend providing a default parameter for status in a destructuring. As follows:

<Formik
  render={({ status = { some: 'value' }) => ( ... )}
/>

Although status could be an empty object by default, what do you think @jaredpalmer?

3reactions
jaredpalmercommented, Feb 8, 2019

Added in 1.5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

InitializationStatus | Google Play services
Listener that returns the status of SDK initialization upon initialization completion. Called when the SDK initialization is complete. Updated ...
Read more >
"Parity Initialization Status: In Progress" for long time
"Parity Initialization Status: In Progress" for long time. Hello, Two weeks ago I installed 6 new hard disks (HP 500GB 6G 7.2K SFF...
Read more >
Initialization Status - SAP Help Portal
Initialization Status. Extensibility Framework initialization is signaled in the completion block of the MAFCore loadWithWindow: andCompletionBlock: API.
Read more >
Variable initialization - The Status Nim style guide
Variable initialization [language.varinit]. Prefer expressions to initialize variables and return values. let x = if a > 4: 5 else: 6 func f(b:...
Read more >
How to initialize the status of a CRD in Kubernetes?
I wonder if there's a way to automatically initialize the field .status.serviceState to be "PENDING" when the CRD is created.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found