codesandbox.io react-typescript react-router-dom not working
Help with Typescript & Reactjs side project
Your entry point as defined in package.json is index.js but there is no code in index.js. That's probably why nothing is rendering. Your shapes.tsx file has an import to NoShape, but I don't see any NoShape file, which is another reason why it would not render.
Start a new project on CodeSandbox and don't delete every bit of starter code in the index file.
More on reddit.comWhat is the URL for codesandbox Vite React-ts template?
I can't find it anywhere. Please help. Thank you!
More on reddit.comReact with Typescript learning curve
Hi! I toyed with this for a few minutes and ended up with this gist.
A few notes on your gist, with line numbers:
-
2: I would use
fetchfor api requests like this unless you have a reason I don't know about to use this tool. -
4: I think the TypeScript style is to capitalize interfaces, possibly even starting them with an I.
-
5: The way I understood it, this component has no props, and doesn't need a Props type.
-
8: This isn't the correct syntax for Array types.
-
16: I'm not really sure why a
refis necessary here. Might be misunderstanding. I've only usedreffor very weird things. Usually to wrap a non-React tool in a React component. -
17: I like to avoid having to do this binding by making my React class methods arrow functions.
-
19: I think you mean
componentDidMounthere. That's probably the appropriate place to make network requests. -
29: This is storing an array of data objects in your component State, not strings as your State interface implies. You use those objects on line 39 later for their
idandtitle. I added a Post interface to the code I linked to. -
36: This input box doesn't do anything yet but I think you probably know that.
I hope that's helpful!
More on reddit.com