-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example of using locales without a global variable
- Loading branch information
1 parent
7b41e8c
commit 888aa1f
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import DatePicker, { registerLocale } from "react-datepicker"; | ||
import fi from "date-fns/locale/fi"; | ||
|
||
export default class LocaleWithoutGlobalVariable extends React.Component { | ||
state = { | ||
startDate: null | ||
}; | ||
|
||
handleChange = date => { | ||
this.setState({ | ||
startDate: date | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="row"> | ||
<pre className="column example__code"> | ||
<code className="jsx"> | ||
{ | ||
"// Note: Make sure to npm install the right version of date-fns as" | ||
} | ||
<br /> | ||
{ | ||
"// specified in packaged.json. The default one may not be compatiable" | ||
} | ||
<br /> | ||
{"// npm install --save date-fns@version"} | ||
<br /> | ||
{"import DatePicker from 'react-datepicker';"} | ||
<br /> | ||
{"import fi from 'date-fns/locale/fi';"} | ||
<br /> | ||
<br /> | ||
{"<DatePicker"} | ||
<br /> | ||
{" selected={this.state.startDate}"} | ||
<br /> | ||
{" onChange={this.handleChange}"} | ||
<br /> | ||
<strong>{" locale={fi}"}</strong> | ||
<br /> | ||
{"/>"} | ||
</code> | ||
</pre> | ||
<div className="column"> | ||
<DatePicker | ||
selected={this.state.startDate} | ||
onChange={this.handleChange} | ||
locale={fi} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |