Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How import statement works in ES6 for React Components [duplicate]

PropTypes is encapsulated in React object in React source code so how this statement is working-

import {PropTypes} from 'react';

like image 539
Abhijeet Srivastava Avatar asked Dec 06 '25 07:12

Abhijeet Srivastava


1 Answers

Modules can export parts of code as default and named exports.

For example, the react library might have something like this

// named export
export function PropTypes(){/*....*/}
// defaul export
export default function(){/*....*/}

So while importing we can import default exports simply as

import React from 'module';

To import named exports we should use curly braces

import {PropTypes} from 'module';

simply we merge the above lines of code

import React, { PropTypes } from 'module'

Read more about modules here

like image 72
StateLess Avatar answered Dec 08 '25 00:12

StateLess