How to access child component functions via refs?

Posted by Jessica Taylor | Updated on | JavaScript


Want to access child component functions via refs? Redux connect accepts an option parameter as the forth parameter. In this option parameter you can set the flag withRef to true. Then you can access functions …

How to conditionally add attributes to React components?

Posted by Jessica Taylor | Updated on | Reactjs


Want to conditionally add attributes to React components? Apparently, for certain attributes, React is intelligent enough to omit the attribute if the value you pass to it is not truthy. For example:

How to pass arguments to functions in React js?

Posted by Jessica Taylor | Updated on | Reactjs


If you want to know how to pass arguments to functions in ReactJS? You can achieve this by using arrow functions. See the below example: onClick the anonymous function is called and executes this.displayAlert(item.email) The …

How to add type check for history object in React?

Posted by Jessica Taylor | Updated on | Reactjs


Want to add type check for history object in React? You can use the RouteComponentProps interface, which declares all props passed by withRouter: The type parameter to RouteComponentProps is the type of the params property …

How to center a component in Material-UI and make it responsive?

Posted by Jessica Taylor | Updated on | Reactjs


If you want to center a component in Material-UI and make it responsive? Since you are going to use this in a login page. Here is a code I used in a Login page using …

Handling ajax with React

Posted by Jessica Taylor | Updated on | Reactjs


In this example, I have shared Handling ajax with React. Just in case anybody stumbled upon this and does not know, jQuery makes it super easy to send AJAX calls. Since React is just JavaScript …

How to register event with useEffect hooks?

Posted by Jessica Taylor | Updated on | Reactjs


Want to register event with useEffect hooks? The best way to go about such scenarios is to see what you are doing in the event handler. If you are simply setting state using previous state, …

How to deploy a React App on Apache web server?

Posted by Jessica Taylor | Updated on | Reactjs


If you want to deploy a React App on Apache web server Following is how the web pack config file should look like check the dist dir and output file specified. I was missing the …

How to test a prop update on React component?

Posted by Jessica Taylor | Updated on | Reactjs


Want to test a prop update on React component It provides a setProps method, that can be called on either a shallow or jsdom wrapper. Reference: https://stackoverflow.com/questions/30614454/how-to-test-a-prop-update-on-react-component

How to call stopPropagation in Reactjs?

Posted by Jessica Taylor | Updated on | Reactjs


In this example, I have shared how to call stopPropagation in Reactjs? The right way is to use .stopPropagation in you application. Your event handlers will be passed instances of SyntheticEvent, a cross-browser wrapper around …

How to detect whether input element is focused within ReactJS?

Posted by Jessica Taylor | Updated on | Reactjs


If you want to detect whether input element is focused within ReactJS? You can run something like this anytime as long as the input node is mounted and there is a reference to it: You …

How to perform an action when post is updated/published in WordPress?

Posted by Jessica Taylor | Updated on | WordPress


If you want to perform an action when post is updated/published in WordPress? The save_post action fires When a post is updated and/or published.

How to add a class to the attachment images in WordPress?

Posted by Jessica Taylor | Updated on | WordPress


If you want to add a class to the attachment images in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.

Publish author posts only with editor approval?

Posted by Jessica Taylor | Updated on | WordPress


I this example, I have shared how to publish author posts only with editor approval in WordPress. Use following code in your theme’s functions.php file OR in site specific plugin. This will add the upload_files …

How to redirect to post if search results only returns one post in WordPress?

Posted by Jessica Taylor | Updated on | WordPress


Want to redirect to post if search results only returns one post in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin. Hope this will help you!