Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active September 9, 2015 17:10
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/5e6a1e3d02ba993c1415 to your computer and use it in GitHub Desktop.
Save ryanflorence/5e6a1e3d02ba993c1415 to your computer and use it in GitHub Desktop.
let Thing = (props) => (
<div>look {props.name}! no state!</div>
)
render(<Thing name="Ma"/>, el)
@n1k0
Copy link

n1k0 commented Sep 1, 2015

Even sexier:

function Thing ({name}) {
  return (
    <div>look {name}! no state!</div>
  )
}

@otodockal
Copy link

or

const Thing = props => <div> look {props.name}! no state! </div>

@bebraw
Copy link

bebraw commented Sep 1, 2015

Maybe

const Thing = ({name}) => <div> look {name}! no state! </div>

@Yomguithereal
Copy link

Should we handle props in events likewise?

function handleClick(name, e) {
  console.log(`The name is "${name}".`);
}

function Thing ({name}) {
  return (
    <div onClick={handleClick.bind(null, name)}>look {name}! no state!</div>
  )
}

@bebraw
Copy link

bebraw commented Sep 1, 2015

@Yomguithereal It might look nicer to push handleClick within Thing scope.

@stoeffel
Copy link

stoeffel commented Sep 2, 2015

Maybe you guys like https://github.com/stoeffel/react-mini. It has a similar approach.

@Yomguithereal
Copy link

@bebraw it would indeed be cleaner.

@stoeffel
Copy link

stoeffel commented Sep 7, 2015

Just to let you know. The new react-mini api is almost the same as you suggested here.
https://github.com/stoeffel/react-mini#api

import pure from 'react-mini/pure';

const Thing = pure(({name}) => {
  function handleClick(e) {
    console.log(`The name is "${name}".`);
  }
  return (
    <div onClick={handleClick}>look {name}! no state!</div>
  )
});

example @jsbin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment