score:0
First of all, react is for SPA, if you use reload just use HTTP (no ajax) to edit. Here is solution for SPA
before coding, the main idea is to update your data after edit, so the road map should be:
1.fetch an array from server and store into state.servers
, and it should be a list of plain objects that contain your server info
2.when you update, you should apply the update to server and then update to local store, as you did in create/delete, edit is most likely the same thing with more data
then your handleSubmit
should be (notice index from iteration as param)
//index from iteration, should be passed from parent component
handleSubmit(index) {
const data = {
querymark: this.props.post_data._id,
servername: this.state.servername,
jpname: this.state.jpname,
ipaddress: this.state.ipaddress,
port: this.state.port,
priority: this.state.priority
}
axios.post('/edit', data).then((response) => {
if (response.data.success === false) {
alert("error");
} else {
//window.location.reload();
dispatch(onEditServer(index,data))
}
}).catch(() => {})
this.setState({
open: false
})
}
onEditServer
should be
const mapDispatchToProps = (dispatch) => {
return {
initServers: (servers) => {
dispatch(initServers(servers))
},
onDeleteServer: (serverIndex) => {
dispatch(deleteServer(serverIndex))
},
onEditServer: (index, data) => {
dispatch(editServer({
type: 'edit',
index,
data,
}))
},
onAddServer: (server) => {
dispatch(addServer(server))
}
}
}
edit reducer
// edit reducer
const edit = (state, action) {
state.servers[action.index] = actions.data
return state
}
then changes will take effect automatically
Source: stackoverflow.com
Related Query
- How can I get the right data from database with react
- How to get a single data element from the database with Redux and React?
- How can I store the data I get from a Promise back into an object with the same key it came from?
- How to get the data from firebase realtime database in react js?
- How can I get the 1st image from each album with an even ID in React using Fetch?
- How to get the data from React Context Consumer outside the render
- How can I get a variable from the path in react router?
- How can I get data from a local file into my React app?
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- How to fetch data in getInitialProps with redux-saga.Then get the response from redux store while in the getInitialProps method?
- How can I use react useContext , to show data from context, in the same component
- How can I get the value from an animated or interpolated value in React Native?
- How can I get React styleguidist to install correctly and get past the peer Dependency issues with react-simple-code-editor: React 16 & 17?
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How can I get the Material-UI DataGrid to read object data from an array?
- How can I get the params from the url with React?
- How do I combine two arrays in react to get a new one with all of the items from the previous two?
- How can I get data from query string using route in react js
- How to fix the state update in react while getting data from firestore database
- How can i get access to the current user inside of react from firebase?
- React.js - When authorizing on the site, if the data is incorrect, how can I get a response with a text error?
- How can I get token from the URL in Nextjs / React App?
- How to dynamically get the images from database into react carousel?
- How to pass data from React client into the Oauth2.0 Google strategy flow with passport.js
- How can I get the data out of a table using Semantic UI React
- How do I get the new updated data from react hooks or useEffect?
- How can I get URI from ApexCharts with React Js
- how to get config data from appsettings.json with asp.net core & react
- React with Redux Saga - How to get data back from axios call
- How to get the data from Redux store using class components in React
More Query from same tag
- Many http requests are being made when I visit a React route even though only one request is being called
- Immutable state is a functional feature in ReactJs?
- React-query: Make new query with useInfiniteQuery with different parameters
- React not communicating with node server
- Filter out records from an array
- Why react hook usestate show an error message
- Async loading script within react component
- Cypress React, cannot find root element to mount the component
- How to set style for map item in react js
- Slide animation for text in container infinitely
- Websocket is undefined immediately after receiving message in react
- Add style to key value in React
- How to fetch data from an endpoint with in ReactJS
- Apply flex property to React mapped items
- react native react-navigation-tabs createMaterialTopTabNavigator animationEnabled no longer working
- How can I use HTML tags from API and display on page?
- Data initialization in useEffect triggers multiple requests
- Radio button checked property not called from Button in a List
- React and ES6 inheritance
- Bootstrap icons not appear in the react js project
- Reactjs switching between components
- Writing to files using File System Access API fails in Electron + Create React App
- Turning Vanilla Javascript into React app in Components
- How to async await in react render function?
- Are TypeScript interfaces recommended for declaration files and React component props?
- Fully functioning countdown timer using React hooks only
- How to fit one div into another div of a modal
- How can i change className to active on li on exact route in reactJS
- Delete an item with ReactJS
- Components not rendered dynamically