I'm trying to make my life easier by using type-specific objects in my javascript react project (typescript is unfortunately not an option). This is the code snippet that is causing the issue:
const [projectsList, setProjectsList] = useState<Project>(testProject);
And my model looks like:
export class Project {
constructor(id, name, pm, projectType, start, end, expectedEnd, state, progress, publishDate, wave ) {
this.id = id;
this.name = name;
this.pm = pm;
this.projectType = projectType;
this.start = start;
this.end = end;
this.expectedEnd = expectedEnd;
this.state = state;
this.progress = progress;
this.publishDate = publishDate;
this.wave = wave;
}
}
Without even sending it an object I'm getting this error in the page:
Uncaught TypeError: boolean false is not iterable (cannot read property Symbol(Symbol.iterator))
Is this not the correct way to ensure type specificity in Javascript React projects?
I'm getting my info from these resources:
- Set types on useState React Hook with TypeScript (I'm aware it says typescript but it was a starting point)
- https://github.com/DefinitelyTyped/DefinitelyTyped/blob/ba2bb0f/types/react/index.d.ts#L916 (obtained as link from above which unfortunately no longer exists)
- https://basarat.gitbook.io/typescript/docs/styleguide/styleguide.html#interface (obtained as link from above which unfortunately no longer exists
- https://codedamn.com/news/reactjs/usestate-hook-typescript (says that you can use type on state but in literally one sentence - no mention of how to instantiate or access the object)
As the project is still in the early phases I'm expecting this object to increase in size. Using a model in this way would greatly simplify having to look up the object keys.
Any help would be much appreciated.
If a (non-working) example would help then let me know and I can quickly put one together.
Cheers!