10 examples of 'moment in react js' in JavaScript

Every line of 'moment in react js' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
206newMoment(...args) {
207 let m = null
208
209 if (args.length < 1) {
210 // if no args, use the current date/time (cannot pass in null otherwise time is zeroed)
211 m = moment()
212 }
213 else {
214 m = moment(...args)
215 }
216
217 m.utc()
218 m.locale(this.config.lang)
219 return m
220}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1532componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
1533 var value = nextProps.value;
1534 var selectedValue = nextProps.selectedValue;
1535
1536 if ('value' in nextProps) {
1537 value = value || nextProps.defaultValue || getNowByCurrentStateValue(this.state.value);
1538 this.setState({
1539 value: value
1540 });
1541 }
1542 if ('selectedValue' in nextProps) {
1543 this.setState({
1544 selectedValue: selectedValue
1545 });
1546 }
1547},
30export function useMoment() {
31 const { i18n } = useTranslations();
32 const { currentUser } = useCurrentUser();
33 const { timezone } = attributesFor(currentUser);
34
35 moment.locale(i18n.language);
36
37 return {
38 moment,
39 timezone: timezone || moment.tz.guess(),
40 };
41}
22getMoment() {
23 let mom = this.props.moment ? this.props.moment.clone() : moment();
24
25 if (this.props.locale) {
26 mom = mom.locale(this.props.locale);
27 }
28
29 return mom;
30}
41export function checkDateValue(props, propName, componentName) {
42 // 支持传入 moment 对象或字符串,字符串不检测是否为日期字符串
43 if (
44 props[propName] &&
45 !moment.isMoment(props[propName]) &&
46 typeof props[propName] !== 'string'
47 ) {
48 return new Error(
49 `Invalid prop ${propName} supplied to ${componentName}. Required a moment object or format date string!`
50 );
51 }
52}
49function reRender() {
50
51 var now = moment();
52 if (now.hour() === time.hour() && now.minute() === time.minute()) return;
53
54 time.hour( now.hour() );
55 time.minute( now.minute() );
56
57 React.render(
58 React.createElement(App, {
59 time: time,
60 timezones: timezones
61 }),
62 targetNode
63 );
64
65}
159static getDerivedStateFromProps(nextProps, prevState) {
160 const { selectedDate, value } = nextProps;
161 let nextDateValue = selectedDate;
162
163 // Use the value for a controlled component if one is provided.
164 if (value !== undefined && value !== null) {
165 nextDateValue = value;
166 }
167
168 if (nextDateValue !== prevState.prevPropsSelectedDate) {
169 const nextSelectedDate = DateUtil.createSafeDate(nextDateValue);
170
171 if (nextSelectedDate) {
172 return {
173 selectedDate: nextSelectedDate,
174 prevPropsSelectedDate: nextDateValue,
175 };
176 }
177
178 return {
179 prevPropsSelectedDate: nextDateValue,
180 };
181 }
182
183 return null;
184}
14valueStringToMoment (stringValue) {
15 if (stringValue) {
16 const momentValue = moment(stringValue)
17 if (momentValue.isValid()) {
18 return momentValue
19 }
20 }
21 return null
22}
26function setMomentLocale(locale: Locale) {
27 if (locale && locale.locale) {
28 interopDefault(moment).locale(locale.locale);
29 } else {
30 interopDefault(moment).locale('en');
31 }
32}
6constructor(props) {
7 super(props);
8 this.state = {
9 value: momentJalaali('1396/7/6', 'jYYYY/jM/jD')
10 };
11}

Related snippets