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.

Events not consistently passed to wrapped React components

See original GitHub issue

Describe the bug

Howdy! I’m using @microsoft/fast-react-wrapper to convert these web-components into React components. I’ve noticed that, for some components, event handler props like onInput and onClick work totally fine, but for others, these props don’t seem to do anything. For example, say I have the following wrapped React components 👇

import { provideReactWrapper } from '@microsoft/fast-react-wrapper';
import {
  vsCodeButton,
  vsCodeDropdown,
  vsCodeOption,
  vsCodeTextField,
} from '@vscode/webview-ui-toolkit';

const { wrap } = provideReactWrapper(React, provideFASTDesignSystem());

const VSCodeButton = wrap(vsCodeButton());
const VSCodeDropdown = wrap(vsCodeDropdown());
const VSCodeOption = wrap(vsCodeOption());
const VSCodeTextField = wrap(vsCodeTextField());

I’m able to use the onClick prop of the VSCodeButton component without trouble.

<VSCodeButton
  onClick={() => {
    console.log('works! ✅');
  }}
>
  Click Me
</VSCodeButton>

Likewise, the onInput prop of the VSCodeTextField component works just fine.

<VSCodeTextField
  onInput={(e) => {
    console.log('i see this logged ✅');
  }}
/>

However, the onChange prop of VSCodeDropdown never seems to fire.

<VSCodeDropdown
  onChange={(e) => {
    console.log('never works ❌');
  }}
>
  <VSCodeOption>Value #1</VSCodeOption>
  <VSCodeOption>Value #2</VSCodeOption>
  <VSCodeOption>Value #3</VSCodeOption>
</VSCodeDropdown>

Additionally, I’ve noticed that the prop types for the generated components aren’t totally right. Here, appearance should be a valid prop, but TS throws an error.

Screen Shot 2021-11-03 at 10 16 29 AM

Note that this doesn’t happen for the wrapped fastButton component.

import { fastButton, provideFASTDesignSystem } from '@microsoft/fast-components';

const { wrap } = provideReactWrapper(React, provideFASTDesignSystem());

const FastButton = wrap(fastButton());
Screen Shot 2021-11-03 at 10 17 54 AM

Expected behavior

I’d expect these props to work consistently across the generated React components, but it’s quite likely that I’m misunderstand the respective APIs of these components.

Do you have any idea what might be going on?

Desktop (please complete the following information):

  • Toolkit Version: 0.8.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
hawkticehurstcommented, Nov 3, 2021

Thanks, @mattrothenberg!

Some initial quick thoughts/questions are if this lack of prop behavior is showing up in more than the dropdown? If it is only the dropdown, I wonder if this could be related to #181 and subsequently this issue on FAST. 🧐 (cc @chrisdholt for thoughts)

Also weird that the type information for the appearance attribute is not showing up either. I can dive into that more once I start up on the React sample extension work in a few days, but again going to cc @chrisdholt in case he has some immediate thoughts/insights into what might be happening.

1reaction
hawkticehurstcommented, Nov 3, 2021

Ooh, I will happily take you up on that offer! Thank you!

I have some low-hanging issues/bugs that I’m trying to tackle this week, but I’ll set up a time to chat sometime next week once I’m a bit more started up on the React work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. ... Pass props to wrapped component return ( <WrappedComponent...
Read more >
Fix the "not wrapped in act(...)" warning - Kent C. Dodds
The reason for this is because the React team couldn't reasonably add this warning for class components without creating a TON of new...
Read more >
Can I make a React Component listen to bubbling change ...
I need some way to tell my HoC to actually listen to events and not just pass a function. I'm not wrapping input's...
Read more >
How to Wrap One React Component into Another | Pluralsight
This is an important first step to ensure our <WrappedComponent /> receives any new props that are passed into our HOC via JSX....
Read more >
How To Create Wrapper Components in React with Props
Finally, you'll pass components as props to create flexible wrappers ... and refactor components as you create flexible wrapping components.
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