Skip to content

Fix error on complex example #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2020
Merged

Conversation

tteke
Copy link
Contributor

@tteke tteke commented Dec 29, 2019

What: Fixing an error on readme

Why: In the complex example catch already sets error to error.message. So in render, it should just show state.error.

How: Render function updated to just show state.error instead of state.error.message.

Checklist:

  • Documentation added to the
    docs site
  • Tests N/A
  • Typescript definitions updated N/A
  • Ready to be merged

    Yes. Either that or catch shoud update error on the state as error: error instead of error: error.message

Catch already sets error to error.message. So in render it should just show state.error.
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit e170f74:

Sandbox Source
eager-moser-41i1r Configuration
purple-violet-nkv2h Configuration

@codecov
Copy link

codecov bot commented Dec 29, 2019

Codecov Report

Merging #560 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #560   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      3           
  Lines          95     95           
  Branches       15     15           
=====================================
  Hits           95     95

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8db62fe...e170f74. Read the comment docs.

@@ -248,7 +248,7 @@ function Login() {
</div>
<button type="submit">Submit{state.loading ? '...' : null}</button>
</form>
{state.error ? <div role="alert">{state.error.message}</div> : null}
{state.error ? <div role="alert">{state.error}</div> : null}
Copy link

@dkarski dkarski Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I have a question about the above syntax.

Is it some convenience to handle show/hidden a component like in README.md?
{ isTrue ? <Component /> : null }

than (shorter a way)
{ isTrue && <Component /> }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could write a blog post about this for the number of times I talk about it 😅

Basically I've been bitten by this before:

{contacts.length && <RenderContactList contacts={contacts} />}

If contacts.length is 0 then you'll render 0. No good. Shipped that to prod at PayPal. So I never do that and instead I always go with the more explicit version:

{contacts.length ? <RenderContactList contacts={contacts} /> : null}

But you do whatever you like :)

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@kentcdodds kentcdodds merged commit cd3edf4 into testing-library:master Jan 21, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @tteke for docs

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @tteke! 🎉

@tteke
Copy link
Contributor Author

tteke commented Jan 22, 2020

Thanks

@kentcdodds
Copy link
Member

🎉 This PR is included in version 9.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants