I'm working on a project that uses TypeScript as well as React and I am new to both. My question is about interface in TypeScript and how that relates to props and states. What is actually happening? My application doesn't run at all unless I declare interface props and states, but I'm using states through the React constructor function and I've seen examples where all of that information would go into 'interface MyProps' or 'interface MyStates'. Take this code, for example:
"use strict";
import * as React from 'react'
import NavBar from './components/navbar.tsx'
import Jumbotron from './components/jumbotron.tsx';
import ContentPanel from './components/contentPanel.tsx';
import Footer from './components/footer.tsx';
interface MyProps {}
interface MyState {}
class Root extends React.Component <MyProps, MyState> {
constructor(props) {
super(props);
this.state = {
///some stuff in here
};
}
render() {
return (
<div>
<NavBar/>
<Jumbotron content={this.state.hero}/>
<ContentPanel content={this.state.whatIs}/>
<ContentPanel content={this.state.aboutOne}/>
<ContentPanel content={this.state.aboutTwo}/>
<ContentPanel content={this.state.testimonial}/>
<Footer content={this.state.footer}/>
</div>
)
}
}
export default Root;
(I've removed the content in this.state just to post on here). Why do I need interface? What would be the correct way to do this, since I think I'm thinking of this in the JSX way and not the TSX way.