score:11
Accepted answer
you can always add event listeners manually in componentdidmount
using a reference to your element. and remove them in componentwillunmount
.
class example extends component {
componentdidmount() {
this.input.addeventlistener('keypress', this.onkeypress, { passive: false });
}
componentwillunmount() {
this.input.removeeventlistener('keypress', this.onkeypress);
}
onkeypress(e) {
console.log('key pressed');
}
render() {
return (
<someinputelement ref={ref => this.input = ref} />
);
}
}
score:3
just wrap your input with passive listener
import {passivelistener} from 'react-event-injector';
<passivelistener onkeypress={this.somelistener.bind(this)}>
<someinputelement/>
</passivelistener>
Source: stackoverflow.com
Related Query
- How to add passive event listeners in React?
- Is it too expensive to add and remove event listeners on every call of my React custom hook? How to avoid it?
- How to add multiple event listeners for the same react component?
- react how to add event listeners to multiple elements at once
- How to add scroll event in react component
- How can I add onKeyPress event to react material-ui textfield?
- How to add Event in React Functional Component
- How to add arguments to event handler in ES6 React when functions are bound in constructor
- How to add click event with React createElement
- React: How to add onChange functionality inside of Function component using React Hooks? Need onClick event from a checkbox to influence input state
- How to Attach Drag & Drop Event Listeners to a React component
- How to add event listeners to create-react-app default sw.js file
- How Can i Add Event Handlers In Reusable React Component Created from Object Array
- How to add event listener to the div element accessed with ref using react and typescript?
- how to add function on event onclick on array.map in react js
- How to add two functions passed as props to an onChange event in React and Material UI?
- How to add click event listener to Nav.Link in React Bootstrap?
- How can I add onClick event for Ref Element using React Hooks?
- How to correctly add event listener to React useEffect hook?
- how to add onchange event in react js application
- How do you add an keyup event listener to window in a React functional component that only gets added when the app originally loads?
- How do I add an event listener to a React component?
- How to add one event listener for two or more events in react
- How to properly add an event lister to an input when using React
- How to add input text event handler in react
- Im building a React App that requires a pdf to download, in the event the (materialUI) download button is clicked, how can I add that functionality?
- How to add Event Listeners to UseRefs within UseEffect
- how to add pagination and fire row click event in table in react js
- How to add event to react function and re-render function
- How to add scroll event on a React component instead of adding on window object?
More Query from same tag
- Create a yellow circle on mousemove with react
- email otp verification with reactjs
- React-leaflet bounds
- React Cannot read property 'bind' of undefined
- How do I serve a React application from an Spring Boot application?
- How to fix 'flattenChildren(...): Encountered two children with the same key' with React and Semantic UI
- How to change a SASS variable value using React Js?
- React eslint error:Component definition is missing display name
- Performance difference for showing/hiding popup. React
- How Snapshot testing works and what does toMatchSnapshot( ) function do in Jest Snapshot testing for React components?
- How to Use Tableau WDC in a ReactJs app the correct way
- How to get reference to store in react/redux?
- How to test a child component from parent component in react
- Using mod operator in JavaScript to wrap around
- Unable to get object/array size
- setState being called multiple times after await
- Can't pass arguments in useQuery with React-Query + Graphql-Request
- React: Prevent infinite Loop when calling context-functions in useEffect
- Prevent Auto Select of date when maxDate is set - Material UI React JS
- Remove dynamic rendered element from dom in ReactJS
- Problems assigning value with setState
- "SyntaxError: Unexpected token < in JSON at position 0"
- ReactDOM Hello World
- How to concatenate props
- React. Component declaration using fat arrow function (ES6 syntax specification)
- How to webpack React.js using uglify version
- How can I convert the sum of minutes, hours in the 'timelite.js' or 'moment.js'?
- Text exceeding maximum height and width of the container
- React useState hook not working as I would expect
- What is the benefit of SSR: true prop with dynamic imports?