Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

TypeScript error Parameter 'props' implicitly has an 'any' type

$
0
0

I am testing out how to use Context in React but for some reason I cant run the app due the typescript error I get!

Code:

import React from 'react';
import './App.css';


class App extends React.Component {
    render() {
      return <Toolbar theme="dark" />;
    }
  }

  function Toolbar(props) {
    // The Toolbar component must take an extra "theme" prop
    // and pass it to the ThemedButton. This can become painful
    // if every single button in the app needs to know the theme
    // because it would have to be passed through all components.
    return (
      <div>
        <ThemedButton theme={props.theme} />
      </div>
    );
  }

  class ThemedButton extends React.Component {
    render() {
      return <button className={'btn btn-' + this.props.theme}></button>;
    }
  }

export default App;

Error I get:

C:/Users/as/Desktop/React - Mobx -Hooks/react-hooks-mobx/src/App.tsx
TypeScript error in C:/Users/iluli/Desktop/React - Mobx -Hooks/react-hooks-mobx/src/App.tsx(11,20):
Parameter 'props' implicitly has an 'any' type.  TS7006

     9 |   }
    10 |   
  > 11 |   function Toolbar(props) {

Any idea how to fix this and explain the reason why it throws that error?


Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>