luckydev
luckydev

Reputation: 149

How to transfer data from state to mapdispatchtoprops?

How to transfer data from state to mapdispatchtoprops? I get the url of the image and write it to state, then I want to pass this url to dispatch

// State
const [imgUrl, setUrl] = useState(null);

// Map dispatch
const mapDispatchToProps = (dispatch, ownProps) => {
	const { api } = ownProps;
	return {
		fetchLoaded: () => {
			api.addData(imgUrl)
		}
	};
};

Upvotes: 1

Views: 54

Answers (1)

Jayce444
Jayce444

Reputation: 9073

You specify your arguments in mapDispatchToProps:

    fetchLoaded: (imgUrl) => {
        api.addData(imgUrl)
    }

Then pass those arguments when calling the function:

    props.fetchLoaded(imgUrl);

Upvotes: 3

Related Questions