Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Fetching data into CRUD Modal

Im looking to fetch the data onto my CRUD modal. But im unable to populate my modal and "bound dispatchAction" was filled in one of the fields. I will need to populate the relevant fields from my SQL server. Screenshot

import axios from 'axios';
import React,{useState,useEffect,useContext} from 'react'
import { Button, Header, Image, Form, Modal } from 'semantic-ui-react'

const EditStore=({openingModal}) => {
  const [open, openCreateModal] = React.useState(true);

const id = openingModal.id
const [name, setName] = useState(openingModal.name);
const [address, setAddress] = useState(openingModal.address);

// to pass data from main onto modal

useEffect(()=>{
  setName(name)
  setAddress(address)
},[name,address]
)

// to fetch data from SQL server
  const fetchStore=()=>{
    axios
    .get("/Stores/GetStore") 
    .then(({data})=> {
        console.log(data);
        this.setState({
            store2:data,
        });
    })
    .catch((err)=>{
        console.log(err);
    });
};

const editStore = ()=>{
  axios.put(("Stores/PutStore"), {
    Name: name,
    Address: address
  })
  .then(res=>{
    openCreateModal(false);
    setName("");
    setAddress("");
    fetchStore();
  })
  .catch(err=>{
    alert(err);
  })
}

  return (
    <Modal
      open={open}
    >
      <Modal.Header>Edit Store</Modal.Header>
        <Modal.Content>
        <Modal.Description>
          <Form>
    <Form.Field>
      <label>Name</label>
      <input value= {name} onChange={(e) => setName(e.target.value)}/>
    </Form.Field>
    <Form.Field>
      <label>Address</label>
      <input value={address} onChange={(e) => setAddress(e.target.value)}/>
    </Form.Field>
  </Form>
        </Modal.Description>
      </Modal.Content>
      <Modal.Actions>
        <Button color='black' onClick={() => openingModal (false)}>Cancel</Button>
        <Button color="green" onClick={editStore}>Edit</Button>
      </Modal.Actions>
    </Modal>
  )
}

export default EditStore

Tried various functional or class component method but didnt quite worked out.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!