Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #viewset class from python
- class feedbackViewSet(viewsets.ModelViewSet):
- queryset = feedback.objects.all()
- permission_classes = [
- permissions.AllowAny
- ]
- serializer_class = feedbackSerializer
- //axios post method
- export const addFeedback = feedback => dispatch => {
- axios
- .post("/api/feedbacks/", feedback)
- .then(res => {
- dispatch({
- type: ADD_FEEDBACK,
- payload: res.data
- });
- })
- .catch(err => console.log(err));
- };
- //form component code
- import React, { Component } from "react";
- import { connect } from "react-redux";
- import PropTypes from "prop-types";
- import { addFeedback } from "../../actions/feedbacks";
- export class Form extends Component {
- state = {
- name: "",
- email: "",
- description: ""
- };
- static propTypes = {
- addFeedback: PropTypes.func.isRequired
- };
- onChange = e => this.setState({ [e.target.name]: e.target.value });
- onSubmit = e => {
- e.preventDefault();
- const { name, email, description } = this.state;
- const feedback = { name, email, description };
- this.props.addFeedback(feedback);
- };
- render() {
- const { name, email, description } = this.state;
- return (
- //some form generation code
- );
- }
- }
- export default connect(
- null,
- { addFeedback }
- )(Form);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement