Home > Net >  React TSX to React js : How to convert TS functions to JS?
React TSX to React js : How to convert TS functions to JS?

Time:06-28

I need to convert some functionality from ts to js, please check below TS code

interface IDashboardPageState {
  serviceComponents: Array<React.Ref<DashboardItem>>
}

{this.props.services.map((text: string, index) => {
              let textUrl = text.replace(/\s/g, '');
              return (
                <Grid item xs={4} key={text} >
                  <DashboardItem ref={this.state.serviceComponents[text]} itemName={text} itemDesc={text} />
                </Grid>
              )
            })}

I need to convert the above code to js format, how to achieve it.

CodePudding user response:

You just remove parts that look like typescript:

{this.props.services.map((text, index) => {
              let textUrl = text.replace(/\s/g, '');
              return (
                <Grid item xs={4} key={text} >
                  <DashboardItem ref={this.state.serviceComponents[text]} itemName={text} itemDesc={text} />
                </Grid>
              )
            })}

CodePudding user response:

If you just need to convert manually i.e. no cli usage. You can use this online tool.

  • Related