Skip to content

Commit

Permalink
fix: state rendering problem solved
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaMajmudar committed Jun 7, 2024
1 parent 016251e commit 5012b16
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions components/GettingStarted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ const GettingStarted = () => {
};

const [options, setOptions] = useState([]);
const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData);
const [selectedSchema, setSelectedSchema] = useState(
'/getting-started-examples/schemas/default.json',
);
const [instances, setInstances] = useState([
{
name: 'Valid instance',
Expand All @@ -84,17 +80,14 @@ const GettingStarted = () => {
},
]);

const [selectedInstance, setSelectedInstance] = useState(
'/getting-started-examples/instances/default-ok.json',
);
const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData);
const [fetchedInstance, setFetchedInstance] = useState({});

useEffect(() => {
fetchData().then((data) => setOptions(data));
}, []);

const handleChange = async (e: any) => {
setSelectedSchema(e.target.value);
const handleSchemaChange = async (e: any) => {
const selectedSchemaObj = options.find(
// @ts-ignore
(schema) => schema.file === e.target.value,
Expand All @@ -103,7 +96,7 @@ const GettingStarted = () => {
if (selectedSchemaObj) {
// @ts-ignore
setInstances(selectedSchemaObj.instances);
const schemaResponse = await fetch(selectedSchema);
const schemaResponse = await fetch(e.target.value);
const schemaData = await schemaResponse.json();
setFetchedSchema(schemaData);
} else {
Expand All @@ -113,9 +106,7 @@ const GettingStarted = () => {
};

const handleInstanceChange = async (e: any) => {
setSelectedInstance(e.target.value);

const instanceResponse = await fetch(selectedInstance);
const instanceResponse = await fetch(e.target.value);
const instanceData = await instanceResponse.json();
setFetchedInstance(instanceData);
};
Expand All @@ -129,7 +120,7 @@ const GettingStarted = () => {
name='Select a JSON Schema Validator'
className='p-2 border dark:border-slate-300 border-slate-800 dark:bg-slate-900 rounded-md max-sm:text-[12px]'
id='Examples'
onChange={handleChange}
onChange={handleSchemaChange}
>
{options.map((option: any, id: number) => (
<option key={id} value={option.file}>
Expand Down Expand Up @@ -216,7 +207,7 @@ const GettingStarted = () => {
className: 'mr-8',
}}
>
{JSON.stringify(fetchedInstance, null, 2)}{' '}
{JSON.stringify(fetchedInstance, null, 2)}
</Highlight>
</div>
</div>
Expand Down

0 comments on commit 5012b16

Please sign in to comment.