-1

I have a static JSON file in my apache server and I want my react application to access the static JSON file and show its content

The idea behind is I have a Terms and Condition page in my application my react application will cover all the skeleton (App bar, logo, Navigation buttons ..) of the T&C page but I want the content of my T&C page to be loaded from the static JSON file that I place on my server so that if I want to make any change to the T&C I only update the JSON file and no need to rebuild my application

FYI - I am using create react app and not webpack

How do I achieve this?

4
  • what have you tried so far? Commented Jul 30, 2024 at 15:49
  • Why not just fetch it? Commented Jul 30, 2024 at 15:57
  • "FYI - I am using create react app and not webpack"... CRA uses Webpack Commented Jul 31, 2024 at 2:10
  • I created a static HTML file and fetched it from my AWS I moved away from the idea of using JSON Commented Jul 31, 2024 at 17:32

1 Answer 1

0

Just fetch the file.

let [jsonData, setJsonData] = useState();

async function loadData() {
    let res = await fetch("url");
    setJsonData(await res.json());
}

useEffect(() => {
    loadData();
}, []);

You may want to add error handling.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.