you should bind the function to this
as the ESLint error says "Expected 'this' to be used by class method 'getUrlParams'
getUrlParams = (queryString) => { .... }
as you are not using getUrlParams
during render (like onClick()
) so the above technique is good which we can call it “usage of arrow function in class property”.
there are other ways of binding too:
- binding in constructor
this.getUrlParams=this.getUrlParams.bind(this)
- arrow function in render e.g.
onClick={()=>this.getUrlParams()}
assumed that function does not have params. - and
React.createClass
which with ES6 does not make sense 🙂
Related Posts:
- React with ES7: Uncaught TypeError: Cannot read property ‘state’ of undefined
- React eslint error missing in props validation
- ESLint Parsing error: Unexpected token
- How to scroll to an element?
- Cannot read property ‘bind’ of undefined. React.js
- How to add multiple classes to a ReactJS Component?
- This.props.dispatch not a function – React-Redux
- How to add a keyboard listener to my onClick handler?
- How to add a keyboard listener to my onClick handler?
- where is create-react-app webpack config and files?
- JSX not allowed in files with extension ‘ .js’ with eslint-config-airbnb
- Getting “Cannot call a class as a function” in my React Project
- “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
- Invariant Violation: Objects are not valid as a React child
- What’s the difference between using “let” and “var”?
- What is Virtual DOM?
- How to use Redirect in the new react-router-dom of Reactjs
- How to fix “Cannot read property ‘addEventListener’ of null” error [duplicate]
- React.js: Set innerHTML vs dangerouslySetInnerHTML
- React – uncaught TypeError: Cannot read property ‘setState’ of undefined
- How to do a redirect to another route with react-router?
- Jest spy on functionality
- Difference between npx and npm?
- Reactjs – Form input validation
- Error Running React Native App From Terminal (iOS)
- Axios Delete request with body and headers?
- How to implement navbar using react
- Loop inside React JSX
- Understanding React-Redux and mapStateToProps()
- how to render a react component using ReactDOM Render
- Node.js – SyntaxError: Unexpected token import
- Console logging for react?
- Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag
- ‘react-scripts’ is not recognized as an internal or external command
- After $npm install, Getting Error: Cannot find module ‘../lib/utils/unsupported.js’
- React Native: this.setState is not a function
- Node.js – SyntaxError: Unexpected token import
- React: trigger onChange if input value is changing by state?
- forEach is not a function error with JavaScript array
- You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react
- React-Router only one child
- What does the className attribute mean in JSX?
- What is prevState in ReactJS? [duplicate]
- React Hook Warnings for async function in useEffect: useEffect function must return a cleanup function or nothing
- Using Node.js require vs. ES6 import/export
- React – TypeError: Cannot read property ‘props’ of undefined
- Cannot find module ‘@angular-devkit/core’
- What is the difference between state and props in React?
- OnChange event using React JS for drop down
- How can I mock an ES6 module import using Jest?
- React Context vs React Redux, when should I use each one?
- Setting onSubmit in React.js
- How to import image (.svg, .png ) in a React Component
- How can I quickly retrieve a value from a MapIterator returned from Object.keys function?
- ReactJS: setTimeout() not working?
- React Uncaught Error: Target container is not a DOM element [duplicate]
- How to refresh a Page using react-route Link
- React Error: Target Container is not a DOM Element
- How to implement authenticated routes in React Router 4?
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- Console is throwing Unterminated JSX contents error
- How to handle the `onKeyPress` event in ReactJS?
- setInterval in a React app
- How do you Hover in ReactJS? – onMouseLeave not registered during fast hover over
- Expected linebreaks to be ‘LF’ but found ‘CRLF’ linebreak-style
- ReactJS: setTimeout() not working?
- Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
- Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
- React.js – Can’t read property of undefined
- how to download file in react js
- Trying to use fetch and pass in mode: no-cors
- onEnter not called in React-Router
- Pass react component as props
- Objects are not valid as a React child. If you meant to render a collection of children, use an array instead
- Why use Redux over Facebook Flux?
- Local package.json exists, but node_modules missing
- react router v^4.0.0 Uncaught TypeError: Cannot read property ‘location’ of undefined
- Access Control Origin Header error using Axios
- Cannot read property ‘getHostNode’ of null
- Eslint: How to disable “unexpected console statement” in Node.js?
- how to use react require syntax?
- onClick not working React js
- e.target.value on an input field ReactJs, how does it work?
- Uncaught Invariant Violation: Rendered more hooks than during the previous render
- Jest encountered an unexpected token
- ReactJS – .JS vs .JSX
- ReactJS: Maximum update depth exceeded error
- React, Uncaught ReferenceError: ReactDOM is not defined
- How to allow CORS in react.js?
- Does ECMAScript 6 have a convention for abstract classes?
- What do these three dots in React do?
- How to disable button in React.js
- What does “export default” do in JSX?
- Update style of a component onScroll in React.js
- .filter is not a functionÂ
- Correct modification of state arrays in React.js
- Must use destructuring props assignment
- “React.Children.only expected to receive a single React element child” error when putting
and in a - Error: Couldn’t find preset “es2015” relative to directory “/Users/username”
- Await is a reserved word error inside async function