score:2
I think I found the issue and though it'd be OK to post my answer on stackoverflow to help others if anyone ever faces the same problem. I was putting the react-plaid-link inside the tags. The react-plaid-link returns a button which according to the html standard a button inside a form without "type" attribute acts like a submit button. Same goes here in my case which I click the the button it submit the form which causes refreshing page. I fixed the issue by just removing the tags. My updated code looks like this.
import React, {Component} from 'react';
import BuggyApi from "../../services/BuggyApi";
import BlockUi from "react-block-ui";
import ReactPlaid from 'react-plaid'
class Integration extends Component{
state={
plaid_public_key: "",
plaid_public_token: "",
blocking: false,
isSuccess: false,
errorMessage: [],
open: false,
plaidData: [],
};
componentWillMount(){
new BuggyApi().getPlaidPublicKey().then((response)=>{
console.log(response.data);
if(response.status===200){
this.setState({
plaid_public_key: response.data.public_key
});
}
}).catch((error)=>{
})
}
handleOnExit = (error, metadata)=>{
if (error != null) {
console.log('link: user exited');
console.log(error, metadata);
}
};
handleOnLoad =()=>{
console.log('link: loaded');
};
handleOnEvent =(eventname, metadata)=>{
console.log('link: user event', eventname, metadata);
};
handleOnSuccess = (public_token, metadata) => {
console.log('public_token: ' + public_token);
console.log('account ID: ' + metadata.account_id);
};
componentDidMount(){
const script = document.createElement("script");
script.src = "https://cdn.plaid.com/link/v2/stable/link-initialize.js";
script.async = true;
document.body.appendChild(script);
}
render(){
return(
<div className="page-wrapper">
<div className="content container-fluid">
<div className="row">
<div className="col-xs-8">
<h4 className="page-title">Integration</h4>
</div>
<div className="col-xs-4 text-right m-b-30">
</div>
</div>
<div className="row">
<div className="col-md-12">
<div className="text-center">
<h4 className="modal-title">
Link your bank account
</h4>
</div>
<br/>
<br/>
{(this.state.isSuccess)?
<div className="row">
<div className="col-sm-6 col-sm-offset-3">
<div className="alert alert-success">
<strong>Success!</strong> Settings updated successfully!
</div>
</div>
</div>:null
}
{(this.state.errorMessage.length>0)?
<div className="row">
<div className="col-sm-6 col-sm-offset-3">
<div className="alert alert-danger">
<ul>
{this.state.errorMessage.map((message,i) =><li key={i}>{message}</li>)}
</ul>
</div>
</div>
</div>:null
}
<BlockUi tag="div" blocking={this.state.blocking}>
<div className="row">
<div className="col-sm-6 col-sm-offset-3">
{(this.state.plaid_public_key!=="")?
<div>
<button onClick={() => this.setState({ open: true})}>Open Plaid</button>
<ReactPlaid
clientName="Arshad"
product={["auth"]}
apiKey={this.state.plaid_public_key}
env='sandbox'
open={this.state.open}
onSuccess={(token, metaData) => this.setState({plaidData: metaData})}
onExit={() => this.setState({open: false})}
/>
</div>:null
}
</div>
</div>
</BlockUi>
</div>
</div>
</div>
</div>
);
};
}
export default Integration;
score:1
Sometimes you need to put the Plaid button inside a form element, in which case, just pass (e) => e.preventDefault()
in as the onClick
handler
<ReactPlaid
clientName="Arshad"
product={["auth"]}
apiKey={this.state.plaid_public_key}
env='sandbox'
open={this.state.open}
onSuccess={(token, metaData) => this.setState({plaidData: metaData})}
onExit={() => this.setState({open: false})}
onClick={(e) => e.preventDefault()}
/>
Source: stackoverflow.com
Related Query
- React Plaid Component Refreshes the page
- React countup animation starts immediately after the page loading , should start when scrolled to the component (without jquery)
- Scroll page to the nested React component on a button click
- React Router - Go back to the last page visited, and not the default component
- React router - pass api data to the linked component to open with a new page
- React InfiniteScroll in a scrollable component on the page
- Refresh the page only once in react class component
- how to update a route in React Router without re-mounting the component in a single page app?
- React Router doesn't load the new page component after redirecting via navigate
- React router redirects the page but component doesn't get rendered
- Scroll down the page to another React component on a button click
- React Router v4 redirect to current page and the component disappears
- Props mix when using the same component multiple times on a page in React
- How does react component pass value to the previous page component
- React Bootstrap using Nav component refreshes the app
- Remove items from the database on leaving or closing the page from a React Component
- React Router v6 Link component not changing the page at root url
- Got the error "Build optimization failed: found page without a React Component as default export in pages/"
- want to go to SignUp page when clicked on SignUp from the App component in React can some one rectify the code accordingly
- React Redux, load data from the API on first page load ONLY. Render component once data is loaded
- React component disappears when I refresh the page (using react router)
- React Component Loads Halfway Down The Page
- How to fix component position start on bottom then move to normal in react js when the page is refreshed
- Force re-render the react component in the jquery single page application or in static html site?
- Why is React Bootstrap Card not showing in the browser? The page is empty despite the component being used
- React Router: Reload home page when clicking on the site's logo while at the Home component
- React <Nav.Link href > trying to link and scroll to one of the <div> in another component on the same page
- Callback function not automatically re-rendering the react component page
- Linking to a different react component on the same page
- React form refreshes the entire page onSubmit and setState not working
More Query from same tag
- How to get the DOM node of a child
- Using onClick and React AutoBind
- typscript component type parameter
- Sign-in page wont show up
- Migrating from Redux to Redux toolkit
- Javascript merge the values of 4 arrays into one object
- React: is it true that react completes all updates within one cycle of reflow
- Arrow function passing a variable within a prop within a .map
- How to use Google fonts in a React application using Next.js
- React styled-components Navigation bar goes behind sidebar
- Create Ract App build includes unused libraries and unused components
- Cannot read property 'type' of undefined while using react-select with formik
- How to allow a function argument to dynamically only be one value from a typescript interface?
- Copying environment variables into Dockerfile
- How can I put this following code in script tag of helmet in react JS?
- React - Antd Modal Max Width [Modal.info() method]
- React : retrieve info async with useReducer and useContext
- Two dimensional array iteration problem, one ghost element created
- ReactJS can't import 'react-router-dom' anymore
- How to setup Reactjs with Google Analytics?
- Sequence of yield select() is not working
- How do I compare and render the data between several JSON maps in React?
- how to use image in react lazy fallback
- How to open new page and scroll to id leaving the URL unaffected?
- import javascipt jquery file in to react file
- ReactJS - Call a component function from outside for multiple instances
- Connect React App served on dockerized Nginx to Express server
- Change active element in a list using react
- UseEffect not fetching data with axios
- Map diferent arrays into same component