Skip to content

Commit

Permalink
Replace usage of defaultProps
Browse files Browse the repository at this point in the history
Replace usage of defaultProps. This is deprecated and will be removed in future React versions (see facebook/react#16210)
  • Loading branch information
gkielwasser committed Jul 13, 2024
1 parent 511292d commit 442ab84
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/html.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const usedProps = Object.keys(defaultProps)
class HTMLEllipsis extends React.Component {
constructor (props) {
super(props)
this.props = { ...defaultProps, ...props }
this.state = {
html: props.unsafeHTML,
clamped: false
Expand Down Expand Up @@ -240,6 +241,4 @@ class HTMLEllipsis extends React.Component {
}
}

HTMLEllipsis.defaultProps = defaultProps

export default HTMLEllipsis
3 changes: 1 addition & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const usedProps = Object.keys(defaultProps)
class LinesEllipsis extends React.Component {
constructor (props) {
super(props)
this.props = { ...defaultProps, ...props }
this.state = {
text: props.text,
clamped: false
Expand Down Expand Up @@ -185,6 +186,4 @@ class LinesEllipsis extends React.Component {
}
}

LinesEllipsis.defaultProps = defaultProps

export default LinesEllipsis
18 changes: 9 additions & 9 deletions src/loose.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React from 'react'

function LinesEllipsisLoose (props) {
const { component: Component, text, lineHeight, maxLine, style, overflowFallback, ...rest } = props
function LinesEllipsisLoose ({
component: Component = 'div',
text,
lineHeight,
maxLine = 1,
style = {},
overflowFallback = true,
...rest
}) {
const maxLineNumber = +maxLine || 1
let usedStyle = {
...style,
Expand All @@ -28,11 +35,4 @@ function LinesEllipsisLoose (props) {
)
}

LinesEllipsisLoose.defaultProps = {
component: 'div',
maxLine: 1,
style: {},
overflowFallback: true
}

export default LinesEllipsisLoose
9 changes: 6 additions & 3 deletions src/responsiveHOC.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import React from 'react'
import debounce from 'lodash/debounce'
const isBrowser = typeof window !== 'undefined'

const defaultProps = {
innerRef: () => {}
}

export default function responsiveHOC (wait = 150, debounceOptions) {
return Component => {
class Responsive extends React.Component {
constructor (props) {
super(props)
this.props = { ...defaultProps, ...props }
this.state = {
winWidth: isBrowser ? window.innerWidth : 0
}
Expand Down Expand Up @@ -35,9 +40,7 @@ export default function responsiveHOC (wait = 150, debounceOptions) {
}

Responsive.displayName = `Responsive(${Component.displayName || Component.name})`
Responsive.defaultProps = {
innerRef () {}
}

return Responsive
}
}

0 comments on commit 442ab84

Please sign in to comment.