diff --git a/example/full.jsx b/example/full.jsx new file mode 100644 index 0000000..68a5dba --- /dev/null +++ b/example/full.jsx @@ -0,0 +1,306 @@ +// See corresponding: https://reactjs.org/docs/jsx-in-depth.html +// JSX Specification: https://facebook.github.io/jsx/ + + + Click Me + + +// ---------------------------------------- +// ---------------------------------------- + +
+ +// ---------------------------------------- +// ---------------------------------------- +import React from 'react'; +import CustomButton from './CustomButton'; + +function WarningButton() { + // return React.createElement(CustomButton, {color: 'red'}, null); + return ; +} + +// ---------------------------------------- +// ---------------------------------------- +import React from 'react'; + +const MyComponents = { + DatePicker: function DatePicker(props) { + return
Imagine a {props.color} datepicker here.
; + } +} + +function BlueDatePicker() { + return ; +} + +// ---------------------------------------- +// ---------------------------------------- +import React from 'react'; + +// Wrong! This is a component and should have been capitalized: +function hello(props) { + // Correct! This use of
is legitimate because div is a valid HTML tag: + return
Hello {props.toWhat}
; +} + +function HelloWorld() { + // Wrong! React thinks is an HTML tag because it's not capitalized: + return ; +} + +// ---------------------------------------- +// ---------------------------------------- +import React from 'react'; + +// Correct! This is a component and should be capitalized: +function Hello(props) { + // Correct! This use of
is legitimate because div is a valid HTML tag: + return
Hello {props.toWhat}
; +} + +function HelloWorld() { + // Correct! React knows is a component because it's capitalized. + return ; +} + +// ---------------------------------------- +// ---------------------------------------- + +import React from 'react'; +import { PhotoStory, VideoStory } from './stories'; + +const components = { + photo: PhotoStory, + video: VideoStory +}; + +function Story(props) { + // Should be white ! + // || + // \/ + // Wrong! JSX type can't be an expression. + return ; +} + +// ---------------------------------------- +// ---------------------------------------- + + + +// ---------------------------------------- +// ---------------------------------------- + +function NumberDescriber(props) { + let description; + if (props.number % 2 == 0) { + description = even; + } else { + description = odd; + } + return
{props.number} is an {description} number
; +} + + + + + + + + + + + + + +// ---------------------------------------- +// ---------------------------------------- + +function App1() { + return ; +} + +function App2() { + const props = {firstName: 'Ben', lastName: 'Hector'}; + return ; +} + +// ---------------------------------------- +// ---------------------------------------- + +const Button = props => { + const { kind, ...other } = props; + const className = kind === "primary" ? "PrimaryButton" : "SecondaryButton"; + return +
+ ); +}; + +Hello world! + +// ---------------------------------------- +// ---------------------------------------- + +
This is valid HTML & JSX at the same time.
+ +// ---------------------------------------- +// ---------------------------------------- + +
Hello World
+ +
+ Hello World +
+ +
+ Hello + World +
+ +
+ + Hello World +
+ +// ---------------------------------------- +// ---------------------------------------- + + + + + + +// ---------------------------------------- +// ---------------------------------------- + +
+ Here is a list: +
    +
  • Item 1
  • +
  • Item 2
  • +
+
+ +// ---------------------------------------- +// ---------------------------------------- + + + +// ---------------------------------------- +// ---------------------------------------- + +render() { + // No need to wrap list items in an extra element! + return [ + // Don't forget the keys :) +
  • First item
  • , +
  • Second item
  • , +
  • Third item
  • , + ]; +} + +// ---------------------------------------- +// ---------------------------------------- + +foo + +{'foo'} + +// ---------------------------------------- +// ---------------------------------------- + +function Item(props) { + return
  • {props.message}
  • ; +} + +function TodoList() { + const todos = ['finish doc', 'submit pr', 'nag dan to review']; + return ( +
      + {todos.map((message) => )} +
    + ); +} +// ---------------------------------------- +// ---------------------------------------- + +function Hello(props) { + return
    Hello {props.addressee}!
    ; +} + +// ---------------------------------------- +// ---------------------------------------- + +// Calls the children callback numTimes to produce a repeated component +function Repeat(props) { + let items = []; + for (let i = 0; i < props.numTimes; i++) { + items.push(props.children(i)); + } + return
    {items}
    ; +} + +function ListOfTenThings() { + return ( + + {(index) =>
    This is item {index} in the list
    } +
    + ); +} + +// ---------------------------------------- +// ---------------------------------------- + +
    + +
    + +
    {false}
    + +
    {null}
    + +
    {undefined}
    + +
    {true}
    + +// ---------------------------------------- +// ---------------------------------------- + +
    + {showHeader &&
    } + +
    + +// ---------------------------------------- +// ---------------------------------------- + +
    + {props.messages.length && + + } +
    + +// ---------------------------------------- +// ---------------------------------------- + +
    + {props.messages.length > 0 && + + } +
    + +// ---------------------------------------- +// ---------------------------------------- + +
    + My JavaScript variable is {String(myVariable)}. +
    +