Last active
July 18, 2016 12:05
-
-
Save terrierscript/3c470528f0d2380da9a6bb0dcd073112 to your computer and use it in GitHub Desktop.
Recompose でいい感じに Higher-order Components(HoCs)を作る ref: http://qiita.com/inuscript/items/275dc41d0705f63ba95f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3> | |
export default class MainApp extends Component{ | |
isSupportedPlatform(){ | |
if(/*ブラウザが未サポートかの判定*/){ | |
return false | |
} | |
return true | |
} | |
render() { | |
if(!this.isSupportedPlatform()){ | |
return <NotSupportedMessage /> | |
} | |
return ( | |
<div className="SomeApp"> | |
何らかのアプリケーション | |
</div> | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3> | |
export default class MainApp extends Component{ | |
isSupportedPlatform(){ | |
if(/*ブラウザが未サポートかの判定*/){ | |
return false | |
} | |
return true | |
} | |
render() { | |
if(!this.isSupportedPlatform()){ | |
return <NotSupportedMessage /> | |
} | |
return ( | |
<div className="SomeApp"> | |
何らかのアプリケーション | |
</div> | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import branch from 'recompose/branch' | |
import renderComponent from 'recompose/renderComponent' | |
// branchは、下記のように引数を取る | |
// branch(判定関数, trueの時, falseの時) | |
const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3> | |
const SomeMyApp = () => ( | |
<div className="SomeApp"> | |
何らかのアプリケーション | |
</div> | |
) | |
const isSupportedBrowser = () => { | |
if(/*ブラウザが未サポートかの判定*/){ | |
return false | |
} | |
return true | |
} | |
const withBrowserCheck = branch( | |
isSupportedBrowser, | |
component => component, // trueの時は、受け取っていた引数をそのまま流用 | |
renderComponent(NotSupportedMessage) | |
) | |
const MainApp = withBrowserCheck(SomeMyApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import branch from 'recompose/branch' | |
import renderComponent from 'recompose/renderComponent' | |
// branchは、下記のように引数を取る | |
// branch(判定関数, trueの時, falseの時) | |
const NotSupportedMessage = () => <h3>お使いのブラウザはサポートされておりません</h3> | |
const SomeMyApp = () => ( | |
<div className="SomeApp"> | |
何らかのアプリケーション | |
</div> | |
) | |
const isSupportedBrowser = () => { | |
if(/*ブラウザが未サポートかの判定*/){ | |
return false | |
} | |
return true | |
} | |
const withBrowserCheck = branch( | |
isSupportedBrowser, | |
component => component, // trueの時は、受け取っていた引数をそのまま流用 | |
renderComponent(NotSupportedMessage) | |
) | |
const MainApp = withBrowserCheck(SomeMyApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MainApp = compose(withBrowserCheck, withDeviceCheck)(SomeMyApp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment