bezenson / react-odometerjs Goto Github PK
View Code? Open in Web Editor NEWOdometer.js React Component
License: MIT License
Odometer.js React Component
License: MIT License
Hello!
Everything good, except duration.
<Odometer format="( ddd).dd" duration={ 20000 } value={ odometerNumber } />
Regardless if I put 20000 or 500, always takes 3000ms for the animation.
Need fix or I miss something?
Moving the underlying library over to another fork or integrating it entirely will allow us to fix its flaws and improve the component drastically.
I don't know of a well maintained fork, but taking one from the many pull requests on the original repo would be a good place to start.
I found this one which makes displaying currency with odometer.js more effective.
Next.js v12 has recently came out, however, it appears that the newest version completely broke this package.
In development mode we're receiving the following error:
transitionCheckStyles = document.createElement('div').style;
^
ReferenceError: document is not defined
This error also prevents launching website in production mode.
I have confirmed this issue doesn't exist with Next.js v11.
This is not supported by the new React Version 17.0.2
Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"17.0.2" from the root project
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.3.0" from [email protected]
npm ERR! node_modules/react-odometerjs
npm ERR! react-odometerjs@"*" from the root project
Hei,
I tried your plugin using React 16.0.0-beta.5 and it crashes with the error TypeError: Cannot read property 'odometer' of null
Perhaps, react-dom will need to be updated when react 16 will be released.
new Odometer
V:/Git/canard/node_modules/odometer/odometer.js:133
130 | _this = this;
131 | this.options = options;
132 | this.el = this.options.el;
> 133 | if (this.el.odometer != null) {
134 | return this.el.odometer;
135 | }
136 | this.el.odometer = this;
ReactOdometer.componentDidMount
V:/Git/canard/node_modules/react-odometerjs/dist/index.js:43
40 | _createClass(ReactOdometer, [{
41 | key: 'componentDidMount',
42 | value: function componentDidMount() {
> 43 | this.odometer = new _odometer2.default(_extends({
44 | el: _reactDom2.default.findDOMNode(this),
45 | value: this.props.value
46 | }, this.props.options));
$ gatsby build
...
failed Building static HTML for pages - 1.838s
ERROR #95312
"document" is not available during server side rendering.
See our docs page for more info on this error: https://gatsby.dev/debug-html
31 | TRANSITION_END_EVENTS = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd';
32 |
> 33 | transitionCheckStyles = document.createElement('div').style;
| ^
34 |
35 | TRANSITION_SUPPORT = (transitionCheckStyles.transition != null) || (transitionCheckStyles.webkitTransition != null) ||
(transitionCheckStyles.mozTransition != null) || (transitionCheckStyles.oTransition != null);
36 |
WebpackError: ReferenceError: document is not defined
- odometer.js:33
node_modules/odometer/odometer.js:33:1
- odometer.js:653
node_modules/odometer/odometer.js:653:2
- index.js:15
node_modules/react-odometerjs/dist/index.js:15:17
Hi there, I'm using react-odometerjs in Nextjs.
As suggested by the doc, I import it with dynamic import but I this way the number don't animate when change.
Maybe is something else but if I import it without dynamic import, I can see the number animate just before the next render when I get the error "document not defined".
Anyone else having this issue?
I want to use Odometer with specific font when I instantiate the component on the screen.
How can I override the styles for digits? Also, is there any way to keep the animation going so like if it reaches maximum, it can restart from minimum again?
Hello friend. I´m trying to use the lib with .tsx with Next.js but it´s not working.
Could not find a declaration file for module 'react-odometerjs'. '.../node_modules/react-odometerjs/dist/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/react-odometerjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-odometerjs';`ts(7016)
Any tip?
Thank you :)
import dynamic from 'next/dynamic';
const Odometer = dynamic(import('react-odometerjs'), {
ssr: false,
loading: () => 0,
});
import { Container, Content, Title, Item } from './styles';
export function OurNumbers() {
return (
<Container>
<Title>Números</Title>
<Content>
<Item>
<Odometer value={1234} format="(.ddd),dd" />
</Item>
<Item>
<Odometer value={1234} format="(.ddd),dd" />
</Item>
<Item>
<Odometer value={1234} format="(.ddd),dd" />
</Item>
</Content>
</Container>
);
}
Hi, very much looking forward to using this library. But I tried just a demo in create-react-app and the output did not match what I was expecting. The value I entered is 1234
and the output I received was 81,828384
!
My App.js
file in a fresh create-react-app. I copied the options from the odometer docs. Even without it, the value is way off.
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Odometer from 'react-odometerjs';
class App extends Component {
render() {
return (
<div className="App">
<Odometer
value={1234}
format="(,ddd).dd"
options={{
auto: false, // Don't automatically initialize everything with class 'odometer'
selector: '.my-numbers', // Change the selector used to automatically find things to be animated
format: '(,ddd).dd', // Change how digit groups are formatted, and how many digits are shown after the decimal point
duration: 3000, // Change how long the javascript expects the CSS animation to take
theme: 'car', // Specify the theme (if you have more than one theme css file on the page)
animation: 'count'
}}
/>
</div>
);
}
}
export default App;
Any idea what's going on here? I'm lost.
Thanks!
Rich
Error in ./~/react-odometerjs/index.js
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (6:19)
When trying to render your component. It's showing the error in odometer js file that document is not defined !!
It would be good to have a slightly better example, for example, as found at https://medium.com/@PostgradExpat/create-an-animated-counter-with-react-odometerjs-hubspot-odometer-js-2f32eb103709
That is, an example should show importing a theme. Let me know if you want me to provide one.
I am using version 2.1.0 with react 16.4.1 (If this helps to identify, I can also specify other packages in use).
I am trying to add an odometer to our page reflecting money. I can't seem to get the '$'-sign in front of the number(This is not major, and no biggie if it can't really be done).
My main issue is when I attempt to use format (,ddd).dd, I am still not getting the last d when it is 0.
this.setState({ theMoney: 17.60 });
...
<Odometer value={this.state.theMoney} duration={1000} format='(,ddd).dd'/>
Above results in the odometer still showing "17.6"
I have attempted converting theMoney to a string but, as expected, it is converting back to a number under the hood, so the last 0 still gets lost.
Is this a known issue, or am I just doing something wrong? I admit I am in an unfamiliar codebase, and have not used odometer before, so it is possible I am just doing something dumb, or missed something in documentation somewhere.
Thanks in advance for any assistance.
transitionCheckStyles = document.createElement('div').style;
^
ReferenceError: document is not defined
at Object.<anonymous> (/home/xxx/node_modules/odometer/odometer.js:33:3)
at Object.<anonymous> (/home/xxx/node_modules/odometer/odometer.js:653:4)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/xxx/node_modules/babel-register/lib/node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Module._load (internal/modules/cjs/loader.js:520:3)
at Function.module._load (/home/xxx/node_modules/piping/lib/piping.js:218:16)
at Module.require (internal/modules/cjs/loader.js:626:17)
import Odometer from 'react-odometerjs'
{this.state.someNumber ? <Odometer value={this.state.someNumber} format="(,ddd)" /> : '--'}
It is very sad that after 3 days trying I still fail to integrate Odometer js in Next js. I can't understand where I wrong in my code. Here is my code in CodeSandBox - https://codesandbox.io/s/long-moon-z9zqu
Please see the code and solve the problem who can. It will be very help full for me.
Correct syntax for dynamic import requires a callback, such as:
const Odometer = dynamic(() => import("react-odometerjs"), {
ssr: false,
loading: () => <div>0</div>,
})
error An unexpected error occurred: "https://registry.npmjs.org/@types%2freact-odometerjs: Not found".
Not sure why. The Odometer module was working fine and then it broke.
<Odometer value={1234} format="(,ddd).dd" />
output
81,828384
Anyone know why?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.