K
K
KnightForce2018-03-25 16:44:05
React Native
KnightForce, 2018-03-25 16:44:05

React Native. What does this declaration Component and function (data: Object): {[name: string]: number} {} mean?

I opened someone else's Js code in the React Native project and saw such a function declaration there.
How many searched did not find an explanation.
1)
When creating a pure React project.

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
      </View>
    );
  }
}

By what rules does type Props = {}; ?
Why Component
2 is needed)
export function create(data: Object): {[name: string]: number} {}

How does it work and most importantly where can I read about it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nd0ut, 2018-03-25
@nd0ut

It's not just JavaScript, but TypeScript or Flow.

type props = {}
is a type alias. More details in the documentation: www.typescriptlang.org/docs/handbook/advanced-type... or https://flow.org/en/docs/types/aliases/
Regarding the use of the component, yes, you are right, in this In this case, it was preferable to use a pure function, because the component is stateless. Probably, the author assumed that in the future there would be stateful and used the class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question