This plugin allows you to use arrow functions like do expressions.
const shows = ["Death Note", "Steins;Gate", "Maho shojo XD"];
const nextShow = prevShow => {
const prevIndex = shows.findIndex(show => show === prevShow);
shows[(prevIndex + 1) % shows.length];
};
const getUserNav = () => {
<UserConsumer>
{user => {
if (user) {
<span>Hello {user.name}!</span>;
} else {
<a onClick={showLogin}>Login</a>;
}
}}
</UserConsumer>;
};
npm install --save-dev babel-plugin-arrow-functions-implicit-return
{
"plugins": ["arrow-functions-implicit-return"]
}
babel --plugins arrow-functions-implicit-return script.js
require("babel-core").transform("code", {
plugins: ["arrow-functions-implicit-return"]
});