window.innerWidth in real time

Posted by Prem Tiwari | Updated on | Reactjs


window.innerWidth in real time. Use the below example code to window.innerWidth in real time.

Get the size of the screen current web page and browser window

Posted by Prem Tiwari | Updated on | Reactjs


You can get the size of the window or document with jQuery: For screen size you can use the screen object:

React-router and iframe browser history

Posted by Prem Tiwari | Updated on | Reactjs


React-router and iframe browser history. You have to replace a new iframe every time the src change. By doing that without change things much, just add difference key to your iframe every time you change …

How do I use reactjs with Google DFP/AdSense

Posted by Prem Tiwari | Updated on | Reactjs


Here’s a simple component that handles displaying ads, taking into account viewability best practices.

How to nest classes in css modules and react?

Posted by Prem Tiwari | Updated on | Reactjs


How to nest classes in css modules and react. I think that I just overdid it in my mind. Instead of writing styles.header.menu I could just write styles.menu, even if it was nested.

Hooks and Redux Saga

Posted by Prem Tiwari | Updated on | Reactjs


You can use useReducer hook instead of redux if you want. But if you have a shared state between different components that are deep nested in different branches of DOM tree, implementation with useReducer could …

Updating React component state in Jasmine Test

Posted by Prem Tiwari | Updated on | Reactjs


Updating React component state in Jasmine Test. I don’t know if the previous answer is still true. With React 0.11.1, this code works fine:

Reactjs attach event from parent to children

Posted by Prem Tiwari | Updated on | Reactjs


You can’t call methods on child components in React. You can only set properties. (The child is actually a ReactElement which contains information about the class and associated properties. It is not an instance of …

Can’t set state in componentWillMount

Posted by Prem Tiwari | Updated on | Reactjs


You’re making an API call which is async. So, the setState will be invoke only after receiving the data. It does not do anything with componentWillMount or componentDidMount. You need to handle the empty message …

How do I trigger a change event on radio buttons in react-testing-library?

Posted by Prem Tiwari | Updated on | Reactjs


How do I trigger a change event on radio buttons in react-testing-library? First, you don’t have to call rerender. You use rerender only when you want the component to receive different props. See link. Whenever …

How to use useRouter() from next.js in a class component?

Posted by Prem Tiwari | Updated on | Reactjs


How to use useRouter() from next.js in a class component? In general, it’s possible to create a wrapper functional component to pass custom hooks into class components via props (but not useful in this case):

Webpack exclude entries for CommonsChunkPlugin

Posted by Prem Tiwari | Updated on | Reactjs


It’s because the first parameter for CommonsChunkPlugin is “common” where it should be “lib”. The plugin picks up the entry with a name matching with the value of its first parameter.

Why can’t I access state and props inside event handler

Posted by Prem Tiwari | Updated on | Reactjs


Why can’t I access state and props inside event handler? As of React .14 event handlers are not being auto-bound to the scope of the component. You can use the dirty .bind(this) method which I …

Re-render Reactjs components for print

Posted by Prem Tiwari | Updated on | Reactjs


Use media query to target portrait and landscape print:

React passing object through props

Posted by Prem Tiwari | Updated on | Reactjs


React passing object through props. I have used this method to pass object through component: