1
votes

I want to send lists(in Content) to mainData and then in mainData I want to set the lists to respone.data (so lists(in Content) is set to response.data) HOW CAN I DO IT ?? please help me... :(

// Content. js

const Content = (props) => {
    const [lists, setLists] = useState(null);
    useEffect(() => {
        mainData(setLists, props.url);
    }, []);

// mainData.js

import axios from 'axios';

export const mainData = async({setLists, url}) => {
    try {
        setLists(null);
        const response = await axios.get(url);
        setLists(response.data);
    } catch(error) {
        console.error(error);
    }
} 
1
You have a typo. mainData should accept two arguments, not a single destructured object... const mainData = async (setLists, url) => { ... }Phil

1 Answers

-1
votes

A GET request is not designed to upload data. You need to make a POST request, and set the {data: "something"} option in the request config for that to work.