how can I use redux so that my values of my form get accesible to other components.Currently I've this:
import React, { Component } from 'react';
class AdminConfig extends Component{
constructor(props){
super(props);
this.state=({
payerName:'',
payerAddress:''
})
this.onPayerNameChange = this.onPayerNameChange.bind(this);
this.onPayerAddressChange = this.onPayerAddressChange.bind(this);
this.onAdminFormSubmit = this.onAdminFormSubmit.bind(this);
}
onPayerNameChange(e){
this.setState({
payerName: e.target.value
})
}
onPayerAddressChange(e){
this.setState({
payerAddress: e.target.value
})
}
onAdminFormSubmit(e){
e.preventDefault()
// I guess here goes the magic
}
render(){
return(
<div className="container ">
<form className="admin-form" onSubmit={this.onAdminFormSubmit}>
<div className="row">
<div className="jumbotron col-md-12">
<h4>PAYER INFORMATION</h4>
</div>
<div className="col-md-6">
<div className="panel panel-primary">
<div className="panel-heading">Payer Name</div>
<div className="panel-body">
<input
onChange={this.onPayerNameChange}
type="text"
className="form-control"
id="payerName"
placeholder="Payer Name" />
<div className="panel-body" id="getResult"><p>Payer Name: {this.state.payerName}</p></div>
</div>
</div>
</div>
<div className="col-md-6">
<div className="panel panel-primary">
<div className="panel-heading">Payer Address</div>
<div className="panel-body">
<input
onChange={this.onPayerAddressChange}
type="text"
className="form-control"
id="payerAddress"
placeholder="Payer Address" />
<div className="panel-body" id="getResult"><p>Payer Address: {this.state.payerAddress}</p></div>
</div>
</div>
</div>
</div>
<button type="submit" className="btn btn-primary btn-lg">Apply config</button>
</form>
</div>
);
}
}
export default AdminConfig
Im using a boilerplate called redux simple starter from Stephen Grider and there is a directory for actions and reducers. Whats next in order to apply redux to my form ?
Related
I am working on a project where if the login detail is valid, we move to the next page ("/home"). But in my case, while it works perfectly good when the email is invalid, it does not go the expected page when the email is valid. Instead, the page only reloads. Although I have done the necessary in the onSubmit function. Please help
class Test extends React.Component {
constructor(){
super();
this.state = emailState;
this.onChange = this.onChange.bind(this);
}
onChange(e) {
this.setState({
email : e.target.value
});
}
emailValidation(){
const regex = /^(([^<>()[\]\.,;:\s#\"]+(\.[^<>()[\]\.,;:\s#\"]+)*)|(\".+\"))#(([^<>()[\]\.,;:\s#\"]+\.)+[^<>()[\]\.,;:\s#\"]{2,})$/i;
if(!this.state.email || regex.test(this.state.email) === false){
this.setState({
error: "Email is not valid"
});
return false;
}
return true;
}
onSubmit(){
if(this.emailValidation()){
console.log(this.state);
this.props.history.push('/home');
}
}
render(){
return (
<div className="login-cot bg-danger" id="layoutAuthentication">
<div id="layoutAuthentication_content">
<main>
<div className="container ">
<div className="row justify-content-center ">
<div className="col-lg-5 ">
<div className="card shadow-lg border-0 rounded-lg mt-5 bg-secondary">
<center><h1 className="bg-warning" style={{padding:"10px",}}><b><BsBugFill /><BsTools /> <BsColumns /> BFP</b></h1></center>
<div className="card-header"><h3 className="text-center my-1"><b>Login</b></h3></div>
<div className="card-body">
<form>
<div className="form-floating mb-3">
<input className="form-control" id="email" type="email"
placeholder="name#example.com"
value={this.state.email}
onChange={this.onChange}
/>
<label for="inputEmail">Email address</label>
<span className="text-danger">{this.state.error}</span>
</div>
<button type ="submit" className="btn btn-success" onClick={()=>this.onSubmit()}>Login</button>
</form>
</div>
<div className="card-footer text-center py-3">
<div className="small"><Link className="text-light" to="/signup">Need an account? Sign up!</Link></div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
)
}
}
Try to use withRouter() function with react , which helps to access the history parameter.
For e.g in your case : export default withRouter(Test);
I am trying to add a spinner but there is a problem while executing the program
import React,{Component} from 'react';
import axios from 'axios';
import LoginFailModal from './LoginFailModal';
class Login extends Component
{
constructor(props)
{
super(props);
this.state = {
username : "",
password : "",
error:false,
loading:false
}
}
inputSet =(e)=> {
//console.log(e.target.name);
this.setState({[e.target.name]:e.target.value})
}
loginCheck =(e)=>{
this.setState({['error']:false});
this.setState({['loading']:true});
e.preventDefault();
var data = {
emph : this.state.username,
password : this.state.password
};
axios.post("url",data).then(response=>{
if(response.data.status=='200')
{
var response_data = response.data.data;
var user_data = {'token':response_data.token,
'user_type':'staf'}
localStorage.setItem('user_data', user_data);
this.setState({['error']:true,['loading']:false});
}
else
{
this.setState({['error']:true,['loading']:false});
}
})
}
render()
{
let {loading} = this.state;
return(
<>
{this.state.error ? (<LoginFailModal/>):""}
<div class="row">
<div className="col-xl-7 col-lg-4 col-md-2">
<img className="bg_img" src="assets/images/bg.jpg" alt=""/>
</div>
<div className="col-xl-5 col-lg-4 col-md-2">
<div className="login">
<img className="login-logo" src="assets/images/login-logo.png" alt=""/>
<form className="input">
<input className="text-field" type="text" name="username" onChange={this.inputSet} placeholder="Username" id=""/>
<input className="text-field" type="password" name="password" onChange={this.inputSet} placeholder="Password" id=""/>
<p className="fp">Forgot Password?</p>
<div className="cal">
<div className="row">
<div col-xl-4 col-lg-2 col-md-2>
<p className="sum">40+40</p>
</div>
<div col-xl-5 col-lg-2 col-md-2>
<input className="get" type="text" name="" placeholder="" id=""/>
</div>
</div>
</div>
<div className="row">
<p className="pl-5 remember"><input type="checkbox" name="remember me" id=""/>
Remember me</p>
</div>
<div className="login_button">
<p style={{color: "red"}}>{this.state.error}</p>
<button className="button" onClick={this.loginCheck}>Login
{loading && <i className="fa fa-refresh fa-spin" style={{color:'white'}}></i>}</button>
</div>
</form>
</div>
</div>
</div>
</>
)
}
}
export default Login;
Hitting submit from http://localhost:3000/newReport.
i have three fields treeselectdropdown, a textbox and a number field. i am setting days in state.
It redirect to http://localhost:3000/newReport?days=10 (if i give no of days as 10).
**import React from 'react';
import TestDropdownTreeSelect from './DropdownTreeSelect';
import Select from 'react-select';
class NewReport extends React.Component{
constructor() {
super();
this.state = {
days:null
};
this.getResults = this.getResults.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleChange({ target }) {
this.setState({
days: target.value
});
}
getResults() {
if(this.state.days!=null || this.state.days!=0)
alert(this.state.days);
fetch('*********************/************/getReportData?libraryName=R1_CONTENT_en_IN')
.then(res => res.text())
.then(text => {
console.log('R4_CONTENT_en_US----------------')
console.log(text);
console.log('R4_CONTENT_en_US----------------')
}).catch(err => {
console.log("ERROR: " + err);
})
}
render(){
return (
<div>
<form required>
<div class="label">
<b>New Report</b>
</div>
<br></br>
<div className="container">
<div class="row">
<div class="col-md-2">
<div class="labelNameLib">
<b>Library</b>
</div></div>
<div class="col-md-4">
<TestDropdownTreeSelect />
</div>
</div>
</div>
<div className="container">
<div className="row">
<div className="col-md-2">
<div class="labelName">
<b>Author</b>
</div>
</div>
<div className="col-md-2">
{/* <Select options={Authors}></Select> */}
<input type="text" ></input>
</div>
<div className="col-md-2"></div>
</div>
</div>
<br></br>
<div className="container">
<div className="row">
<div className="col-md-2">
<div class="labelName">
<b>Expiry Date in Next</b>
</div> </div>
<div className="col-md-2">
<input type="number" required
title="Enter number from 1 to 365"
value={ this.state.days } name="days"
onChange={ this.handleChange }
pattern="[0-9]{1,3}" min="1" max ="365"></input>
</div>
<div className="col-md-1"><b>Days</b></div>
</div>
</div>
<br></br>
<div>
<button type="submit" class="runReport"
onClick={this.getResults}
style={{ backgroundColor: '#FFD700', marginLeft: '15%' }}>Run Report</button>
</div>
<div>
</div>
</form>
</div>
);
}
}**
I am not getting rest api result in console. Why it is redirecting to ?days=10.
i am using fetch for hitting rest api requests
This is the expected behaviour with a form. You test the example on the page, the page is reloaded. To prevent this with JavaScript you have to use event.preventDefault(). Here is the snippet updated:
class NewReport extends React.Component{
getResults(event) {
event.preventDefault();
// ...
}
}
My input is also like a searchbox: I want to be able to search for names on the input but then I want to be able to click a name from the dropdown search results and set the input with that value. I then want to be able to search again if I want to change that value.
Tried using DefaultValue and uncontrolled components, but neither worked. Not sure if I used them right though.
class PublishTest extends Component {
constructor() {
super();
this.state = {
showRows: false,
numberOfRows: ["row"],
search: "",
searchResults: [],
insightListActive: false,
insightTagsActive: false
};
this.hideOrShowRows = this.hideOrShowRows.bind(this);
this.addNewRow = this.addNewRow.bind(this);
this.searchAllUsers = this.searchAllUsers.bind(this);
this.onChangeInsight = this.onChangeInsight.bind(this);
this.clearInput = this.clearInput.bind(this);
this.clearInsightList = this.clearInsightList.bind(this);
this.searchInsightTags = this.searchInsightTags.bind(this);
this.clearTagList = this.clearTagList.bind(this);
}
componentDidMount() {
this.props.getLoginCredential();
this.props.getAllRoles();
}
hideOrShowRows() {
this.setState({
showRows: !this.state.showRows
});
}
addNewRow() {
this.setState({
numberOfRows: [...this.state.numberOfRows, "row"]
});
}
searchAllUsers(e) {
this.setState({
search: e.target.value
});
const searchOption = this.state.search;
fetch("http://localhost:3500/soiapi/", {
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify({
data: [
{
name: "searchUser",
urlparameter: { search: searchOption, appId: "1" },
parameter: ""
}
]
})
})
.then(res => res.json())
.then(data => {
this.setState({
searchResults: data[0]
});
});
}
onChangeInsight = e => {
this.props.insightOnChangeValue(e.target.value);
this.props.searchInsights(e.target.value);
this.setState({
insightListActive: true
});
};
clearInput() {
this.setState({
search: "",
searchResults: []
});
}
clearInsightList() {
this.setState({
insightListActive: false
});
}
searchInsightTags(e) {
this.props.getInsightTags(e.target.value);
this.setState({
insightTagsActive: true
});
}
clearTagList() {
this.setState({
insightTagsActive: false
});
}
render() {
const { searchResults } = this.state;
let rows;
let button;
let icon;
if (this.state.showRows) {
rows = this.state.numberOfRows.map((row, i) => (
<div>
<Row index={i} />
</div>
));
button = (
<button
onClick={this.addNewRow}
className="Button--secondary float-right"
>
Add Row
</button>
);
icon = (
<i aria-hidden="true" className="Icon Icon--minus-small iconFont"></i>
);
} else if (!this.state.showRows) {
icon = (
<i aria-hidden="true" className="Icon Icon--plus-small iconFont"></i>
);
}
if (this.props.user.userDTO) {
const { userDTO } = this.props.user;
const insightSearchResults = this.props.insightReducerValue
.insightList[0];
return (
<div style={{ padding: "5px" }} className="publish-container">
<h4 className="publish-h4">Publish Insights</h4>
<h6 className="publish-h6">Insight Details</h6>
<hr className="line-style" />
<section id="publish-section-1">
<div class="Grid">
<div class="Col Col--3">
<div class="grid-block">
<div className="Form-group publish-insights-input">
<label className="Form-label insight-label">
Insight Name <span className="asterisk">*</span>:
</label>
<div id="insight-container">
<input
type="text"
placeholder="Insight Name"
onChange={this.onChangeInsight}
onFocus={this.clearInsightList}
onBlur={this.clearInsightList}
className="Form-input"
value={this.props.insightReducerValue.insightValue}
/>
{this.state.insightListActive ? (
<InsightList insights={insightSearchResults} />
) : null}
</div>
</div>
</div>
</div>
<div class="Col Col--3">
<div class="grid-block">
<div class="Form-group publish-insights-input">
<label class="Form-label">
Insight Source <span className="asterisk">*</span>:
</label>
<select
id="insight-source"
role="combobox"
class="Form-input"
>
<option
disabled="disabled"
selected="selected"
aria-disabled="true"
>
Choose one
</option>
<option>Tableau</option>
<option>Qlik</option>
<option>D3JS</option>
<option>CXI</option>
</select>
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-2">
<div class="Grid">
<div class="Col Col--6">
<div class="grid-block">
<div className="Form-group publish-insights-input">
<label class="Form-label">
URL <span className="asterisk">*</span>:
</label>
<input type="text" placeholder="URL" class="Form-input" />
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-3">
<div class="Grid">
<div class="Col Col--6">
<div class="grid-block">
<div className="publish-insights-input">
<label class="Form-label">
Description <span className="asterisk">*</span>:
</label>
<textarea
placeholder="Description"
class="Form-input"
></textarea>
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-4">
<div class="Grid">
<div class="Col Col--3">
<div class="grid-block">
<div className="Form-group publish-insights-input">
<label className="Form-label third-div-p">
POC Name <span className="asterisk">*</span>:
</label>
<input
type="text"
placeholder="Name"
className="Form-input"
value={`${userDTO.firstName} ${userDTO.lastName}`}
/>
</div>
</div>
</div>
<div class="Col Col--3">
<div class="grid-block">
<div className="Form-group publish-insights-input">
<label className="Form-label third-div-p">
Group Distro (E-mail Address)
<span className="asterisk">*</span>:
</label>
<input
type="text"
placeholder="Email"
class="Form-input"
value={userDTO.emailAddress}
/>
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-5">
<div class="Grid">
<div class="Col Col--6">
<div class="grid-block">
<div class="Form-group publish-insights-input">
<div class="Form-checkbox is-restricted">
<input
id="restricted"
name="checkboxDefault"
type="checkbox"
/>
<label for="restricted">Is Restricted</label>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-6">
<div class="Grid">
<div class="Col Col--2">
<div class="grid-block">
<div id="tree-section">
<label id="category-label" className="Form-label">
Category <span className="asterisk">*</span>
</label>
<div id="tree-container">
<PublishInsightsTree />
</div>
</div>
</div>
</div>
<div class="Col Col--4">
<div class="grid-block">
<div className="Form-group publish-insights-input">
<label className="Form-label third-div-p">
Add Insight Tags <span className="asterisk">*</span>:
</label>
<input
type="text"
onChange={e => this.searchInsightTags(e)}
onFocus={this.clearTagList}
onBlur={this.clearTagList}
placeholder="Write some insight tags"
className="Form-input"
/>
</div>
{
this.state.insightTagsActive ?
<div>
{
this.props.insightTags ?
<InsightTags tags={this.props.insightTags[0]} />
: null
}
</div>
: null
}
</div>
<div class="grid-block">
<div class="Grid">
<div class="Col Col--7 img-url-input">
<div class="grid-block">
<div
id="file-div"
class="Form-group publish-insights-input"
>
<label class="Form-label">
Image URL <span className="asterisk">*</span>:
</label>
<input
type="text"
placeholder="Insight Name"
class="Form-input"
/>
</div>
</div>
</div>
<div class="Col Col--5">
<div class="grid-block">
<button class="Button--secondary upload-image-button">
Upload Image
</button>
</div>
</div>
<div class="Col Col--7 url-description">
<div class="grid-block">
<p>
Please copy paste the generated URL after uploading
image file.
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-7">
<h6 className="publish-h6">Role Details</h6>
<hr className="line-style" />
</section>
<section id="publish-section-8">
<div class="Grid">
<div class="Col Col--2">
<div class="grid-block">
<label id="roles-label" className="Form-label">
Assign to Role <span className="asterisk">*</span>
</label>
<div id="all-roles">
{this.props.listOfRoles ? (
<ListOfRoles roles={this.props.listOfRoles} />
) : null}
</div>
</div>
</div>
<div class="Col Col--4">
<div class="grid-block assign-user-div">
<label className="Form-label label-spacing">
Assign to Individual User:
</label>
<div className="Form-group">
<textarea
onChange={this.searchAllUsers}
type="text"
placeholder="Look up by EID/Name"
onFocus={this.clearInput}
onBlur={this.clearInput}
className="Form-input assign-user-textarea"
value={this.state.search}
></textarea>
{searchResults.length > 0 ? (
<div id="user-list">
{searchResults ? (
<UserList searchResults={this.state.searchResults} />
) : null}
</div>
) : null}
</div>
</div>
</div>
</div>
</section>
<section id="publish-section-9">
<h6 className="publish-h6 metadata-heading" onClick={this.hideOrShowRows}>
<span id="metadata-icon">{icon}</span>
Metadata Info
</h6>
<hr className="line-style color" />
</section>
<section id="publish-section-10">
<div class="Grid">
<div class="Col Col--12 add-row-col">
<div class="grid-block">{button}</div>
</div>
</div>
{rows}
</section>
</div>
);
} else {
return null;
}
}
}
const mapStateToProps = state => ({
user: state.LoginReducer.loginInfo,
searchUser: state.LoginReducer.searchUser,
insightReducerValue: state.SideDrawerReducer,
listOfRoles: state.LoginReducer.listOfRoles,
insightTags: state.SideDrawerReducer.insightTags
});
export default connect(
mapStateToProps,
{
getLoginCredential,
searchUser,
insightOnChangeValue,
searchInsights,
getAllRoles,
getInsightTags
}
)(PublishTest);
This is the part of the code I need help with:
<input
type="text"
placeholder="Insight Name"
onChange={this.onChangeInsight}
onFocus={this.clearInsightList}
onBlur={this.clearInsightList}
className="Form-input"
value={this.props.insightReducerValue.insightValue}
/>
{this.state.insightListActive ? (
<InsightList insights={insightSearchResults} />
) : null}
Since your code is a little messy, I made a sandbox that fetches some data from a dummy API, stores that data to our local component state. We have a text field where we can type in usernames and a list of matching usernames will appear as a dummy drop, clicking any one of those usernames will set the value in the text field. It's pretty straight forward will give you an idea on how to get started.
EDIT:
Sandbox Link: https://codesandbox.io/s/eloquent-pascal-pf3hd?fontsize=14
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
class App extends React.Component {
state = {
input: "",
users: [],
dropdown: []
};
async componentDidMount() {
let users = await fetch("https://jsonplaceholder.typicode.com/users");
users = await users.json();
this.setState({ users });
}
handleChange = e => {
this.setState({ input: e.target.value }, () => {
let results = this.state.users.filter(user => {
return user.username.indexOf(this.state.input) > -1;
});
this.setState({ dropdown: results });
});
};
handleSelect = username => e => {
this.setState({ input: username }, () => this.setState({ dropdown: [] }));
};
render() {
return (
<div className="App">
<h1>Search</h1>
<input
type="text"
name="input"
onChange={this.handleChange}
value={this.state.input}
/>
{this.state.dropdown.map(d => (
<h3 onClick={this.handleSelect(d.username)} key={d.id}>
{d.username}
</h3>
))}
</div>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Could you start off by loading all possible search results into state or props (e.g. under this.props.searchResults)? Then you could try using the datalist tag. Not quite sure if this was what you were going for, but it looked like something like that could work for you.
<input type="text"
defaultValue={this.props.insightReducerValue.insightValue}
list="inputOptions"
onChange={(e) => console.log("Current input field value: ", e.target.value)} />
<datalist id="inputOptions">
{this.props.searchResults.map((item, key) =>
<option key={key} value={item} />
)}
</datalist>
P.S. Check the supported browsers list under the link.
I want to send that state of a component to the actions file.
My component is a <form> where the user can capture some config that later i want to apply that config to the actions file.
Component Code:
import React, { Component } from 'react';
class AdminConfig extends Component{
constructor(props){
super(props);
this.state=({
baseURL:'BASE_URL',
hospitalName: '',
hospitalExternalID:'1000849',
payerName:'',
payerAddress:''
})
this.onBaseURLChange = this.onBaseURLChange.bind(this);
this.onHospitalNameChange = this.onHospitalNameChange.bind(this);
this.onHospitalExIDChange = this.onHospitalExIDChange.bind(this);
this.onPayerNameChange = this.onPayerNameChange.bind(this);
this.onPayerAddressChange = this.onPayerAddressChange.bind(this);
this.onAdminFormSubmit = this.onAdminFormSubmit.bind(this);
}
onBaseURLChange(e){
this.setState({
baseURL: e.target.value
})
}
onHospitalNameChange(e){
this.setState({
hospitalName: e.target.value
})
}
onHospitalExIDChange(e){
}
onPayerNameChange(e){
this.setState({
payerName: e.target.value
})
}
onPayerAddressChange(e){
this.setState({
payerAddress: e.target.value
})
}
onAdminFormSubmit(e){
e.preventDefault()
// here is where i need to send something like this:
this.props.fetchAdminConfig(this.state.baseURL)
}
render(){
return(
<div className="container ">
<form className="admin-form" onSubmit={this.onAdminFormSubmit}>
<div className="row">
<div className="jumbotron col-md-12">
<h4>API CONFIGURATION</h4>
</div>
<div className="col-md-12">
<div className="panel panel-primary">
<div className="panel-heading">BASE URL</div>
<div className="panel-body">
<input
onChange={this.onBaseURLChange}
type="text"
className="form-control"
id="baseURL"
placeholder="Base URL" />
<div className="panel-body" id="getResult"> <p className="">Base URL: http://{this.state.baseURL}/trucare-api-6.2.1.TC621/6.2.1/api</p></div>
</div>
</div>
</div>
</div>
<div className="row">
<div className="jumbotron col-md-12">
<h4>HOSPITAL INFORMATION</h4>
</div>
<div className="col-md-6">
<div className="panel panel-primary">
<div className="panel-heading">Hospital Name</div>
<div className="panel-body">
<input
onChange={this.onHospitalNameChange}
type="text"
className="form-control"
id="hospitalName"
placeholder="Hospital Name" />
<div className="panel-body" id="getResult"><p className="">Hospital name: {this.state.hospitalName}</p></div>
</div>
</div>
</div>
<div className="col-md-6">
<div className="panel panel-primary">
<div className="panel-heading">Hospital External ID</div>
<div className="panel-body">
<input
onChange={this.onHospitalExIDChange}
type="text"
className="form-control"
id="hospitalEXID"
placeholder="Hospital Name" disabled />
<div className="panel-body" id="getResult"><p>Hospital External ID: {this.state.hospitalExternalID}</p></div>
</div>
</div>
</div>
</div>
<div className="row">
<div className="jumbotron col-md-12">
<h4>PAYER INFORMATION</h4>
</div>
<div className="col-md-6">
<div className="panel panel-primary">
<div className="panel-heading">Payer Name</div>
<div className="panel-body">
<input
onChange={this.onPayerNameChange}
type="text"
className="form-control"
id="payerName"
placeholder="Payer Name" />
<div className="panel-body" id="getResult"><p>Payer Name: {this.state.payerName}</p></div>
</div>
</div>
</div>
<div className="col-md-6">
<div className="panel panel-primary">
<div className="panel-heading">Payer Address</div>
<div className="panel-body">
<input
onChange={this.onPayerAddressChange}
type="text"
className="form-control"
id="payerAddress"
placeholder="Payer Address" />
<div className="panel-body" id="getResult"><p>Payer Address: {this.state.payerAddress}</p></div>
</div>
</div>
</div>
</div>
<button type="submit" className="btn btn-primary btn-lg">Apply config</button>
</form>
</div>
);
}
}
export default AdminConfig
Then on my actions file I have this:
export function fetchAdminConfig(BASE_URL){
...
}
const BASE_URL = //this is where I want to apply the state that I captued on my form
export function fetchUsers() {
const request = axios.post(`${BASE_URL}/endpoint`)
return {
type: FETCH_USERS,
payload: request
};
}
How Can I accomplish this?
Just add a parameter to your action creator function and pass it in!
export function fetchAdminConfig(BASE_URL) {
const request = axios.post(`${BASE_URL}/endpoint`)
return {
type: FETCH_USERS,
payload: request
};
}