I’m building a Django-React application (Django API on its standalone server on port 8000 and React front-end on its standalone server on port 3000) using axios to fetch data from the Django server and Redux to dispatch the data. So, I created the redux action like this:
// GET TRANSACTIONS: /action/transactions.js
import axios from 'axios';
import { GET_TRANSACTIONS } from './types';
export const getTransactions = () => (dispatch) => {
axios.get('http://127.0.0.1:8000/api/transaction')
.then((res) => {
dispatch({
type: GET_TRANSACTIONS,
payload: res.data,
});
}).catch((err) => console.log(err));
};
And in the the React view to get the data from redux store I have this:
// React Views :
import React, {Component,} from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { getTransactions } from '../../../../actions/transactions';
import './transfert.css';
const initialState = {
transactions: [],
};
const propTypes = {
transactions: PropTypes.array.isRequired,
};
class Transfert extends Component {
componentDidMount() {
getTransactions();
}
render() {
return (
<div className="table">
</div>
);
}
}
const mapStateToProps = (state) => ({
transactions: state.transactions.transactions,
});
export default connect(mapStateToProps, { getTransactions })(Transfert);
The problem is that I’m not getting the data from the Django server in the reduxdevtools. It displays nothing, only says: type(pin):"@@INIT". Whereas I should be getting all the transactions from there.
Checking the Django server, I found that the Django console says:
code 400, message Bad request version ('\x9bú|$Lª\x01Þù\x83!ów·È\x803<Æ\x00"ZZ\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00') [27/Jan/2022 15:56:59] You're accessing the development server over HTTPS, but it only supports HTTP.
And I thought of setting the SECURE_SSL_REDIRECT to false in the Django setting. So, I set it there like this:
SECURE_SSL_REDIRECT=False SESSION_COOKIE_SECURE=False CSRF_COOKIE_SECURE=False
But to not avail, I’m still not hitting the right point. All my console logging rendered no result, and I’m even more confused, not knowing whether the problem is in the axios call: axios.get('http://127.0.0.1:8000/api/transaction')
Or from the getTransaction() whitin the React Transaction.js (Rect View). Or is there anything with the
const mapStateToProps = (state) => ({
transactions: state.transactions.transactions,
});
Or with the export default connect(mapStateToProps, { getTransactions })(Transfert);
NOTE: In the transaction.jsx view I earlier called:
componentDidMount() {
this.props.getTransactions();
}
With the this.props but the error says: “Must use destructuring props assignment” That is why I changed it to current one:
componentDidMount() {
getTransactions();
}
Any help is very much appreciated. Here I’m seriously stuck.