useFetchXML

UseFetchXMLExample

src/prod/fetch/useFetchXML.ts

import React from 'react';



export const useFetchXML = (url: string) => {
	const [doc, setDoc] = React.useState<Document | null>(null);

	React.useEffect(() => {
		fetch(url)
			.then(res => res.text())
			.then(text => new window.DOMParser().parseFromString(text, "text/xml"))
			.then(doc => setDoc(doc));
	}, [url]);

	return [doc];
};

dist/prod/fetch/useFetchXML.js

import React from 'react';
export const useFetchXML = (url) => {
    const [doc, setDoc] = React.useState(null);
    React.useEffect(() => {
        fetch(url)
            .then(res => res.text())
            .then(text => new window.DOMParser().parseFromString(text, "text/xml"))
            .then(doc => setDoc(doc));
    }, [url]);
    return [doc];
};

src/prod/fetch/useFetchXML.ts

import React from 'react';



export const useFetchXML = (url: string) => {
	const [doc, setDoc] = React.useState<Document | null>(null);

	React.useEffect(() => {
		fetch(url)
			.then(res => res.text())
			.then(text => new window.DOMParser().parseFromString(text, "text/xml"))
			.then(doc => setDoc(doc));
	}, [url]);

	return [doc];
};