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
property value not found in EventTarget #2099
Comments
I don't see Any chance you can point to a spec that says |
not appear in spec but if i run the code target.value return a value, please see please see controlled components example |
More info: If i do handleClick = ({ target }: { target: EventTarget }) => {
if (!this.containerRef.contains(target)) {
this.props.onClickOut();
}
}; EventTarget This type is incompatible with Node |
I decide to close this issue because not is recommended event.target, instead use refs for this |
@crisys11 can you elaborate and give an example? |
in React
or you can use 'this' for non react apps
|
For others that may be confused by this as I was after recently upgrading flow (for me, to 0.33). see: https://developer.mozilla.org/en/docs/Web/API/EventTarget You can fix these errors by checking if target is an instance of Here's a quick example: _onModeChange(event: SyntheticEvent) {
const {target} = event;
if (!(target instanceof window.HTMLInputElement)) {
return;
}
const newMode = APP_MODES.find(({name}) => {
return name === target.value; // flow now knows `target` is an HTMLInputElement.
});
// [...]
} |
😦 that workaround works but makes the code very odd to read for the sake of this discussion, I'm not using React. I have just a normal div clickhandler that gets the id of the checkbox that was clicked
and get:
|
To be clear, my comment isn't a workaround. This is a feature of Flowtype. Without flow, if you accidentally added this function as a listener to some object that didn't have a target value on its event, it would throw a runtime error. |
If you really don't want to test if the target is HTMLInputElement you can use typecast
|
For what it's worth, |
The React + Flow docs have this example for this case, which uses an intersection type:
You could use |
@jeffgran Yes, it works for me.
|
yes ... one of those things i totally hate about using Flow - such a piece of code looks SO much prettier to read if we just can leave out typing at all... all those instanceof checks and additional puttings into const of explicit types just to fullfill the sanity for flow is really a big pain. Especially if you need 5min to implement the feature and then hacking around for hours just to get flow errors to 0 again. The attitude "you should use refs so this is anyway the wrong way" is also not valid - as there are plenty of cases in real-world applications where a full ref-handling is just "another overkill" where the real solution could be so small/handy (and sexy without typing..) |
I made a type for my event in my
Then at the use site:
|
i'm using flow 0.54.1, and this workaround isn't cutting it all of a sudden, any ideas? |
ok, the latest docs have it covered for anyone else: I used SyntheticEvent, and currentTarget for event. |
Just typing |
Just approving above answers about using currentTarget. Possibly right solution:
|
As i'm using react hooks with material ui which encountered into <InputBase
.....
onChange={(e: SyntheticEvent) => onSearch(e)} // onSearch Sent as a prop
.....
/> this solution bellow dose not work onChange = (e: SyntheticInputEvent<HTMLInputElement>): void => {
this.setState({ value: e.currentTarget.value });
} But this way worked for me. TBH i'm not convinced with this approach but at least prevent types errors. const onSearch = useCallback((e: SyntheticEvent) => {
console.log((e.target as HTMLInputElement).value);
}, []); |
Using |
I ended up using such approach: const onChange = (event: React.FormEvent<HTMLInputElement>) =>
console.log(event.currentTarget.value);
}; |
error: SyntheticKeyboardEvent property
value
: Property not found in EventTargetExample:
The text was updated successfully, but these errors were encountered: