Skip to content

Commit

Permalink
fix: use JavaScript default parameters instead React's defaultProps (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
firejune committed Jan 4, 2024
1 parent f7bd96f commit d5a5146
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 95 deletions.
6 changes: 1 addition & 5 deletions src/core/components/errors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ThrownErrorItem = ( { error, jumpToLine } ) => {
)
}

const SpecErrorItem = ( { error, jumpToLine } ) => {
const SpecErrorItem = ( { error, jumpToLine = null } ) => {
let locationMessage = null

if(error.get("path")) {
Expand Down Expand Up @@ -126,10 +126,6 @@ ThrownErrorItem.propTypes = {
jumpToLine: PropTypes.func
}

ThrownErrorItem.defaultProps = {
jumpToLine: null
}

SpecErrorItem.propTypes = {
error: PropTypes.object.isRequired,
jumpToLine: PropTypes.func
Expand Down
6 changes: 1 addition & 5 deletions src/core/components/highlight-code.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import isFunction from "lodash/isFunction"
import saveAs from "js-file-download"
import { CopyToClipboard } from "react-copy-to-clipboard"

const HighlightCode = ({value, fileName, className, downloadable, getConfigs, canCopy, language}) => {
const HighlightCode = ({value, fileName = "response.txt", className, downloadable, getConfigs, canCopy, language}) => {
const config = isFunction(getConfigs) ? getConfigs() : null
const canSyntaxHighlight = get(config, "syntaxHighlight") !== false && get(config, "syntaxHighlight.activated", true)
const rootRef = useRef(null)
Expand Down Expand Up @@ -82,8 +82,4 @@ HighlightCode.propTypes = {
canCopy: PropTypes.bool
}

HighlightCode.defaultProps = {
fileName: "response.txt"
}

export default HighlightCode
6 changes: 1 addition & 5 deletions src/core/components/providers/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (DomPurify.addHook) {
})
}

function Markdown({ source, className = "", getConfigs }) {
function Markdown({ source, className = "", getConfigs = () => ({ useUnsafeMarkdown: false }) }) {
if (typeof source !== "string") {
return null
}
Expand Down Expand Up @@ -51,10 +51,6 @@ Markdown.propTypes = {
getConfigs: PropTypes.func,
}

Markdown.defaultProps = {
getConfigs: () => ({ useUnsafeMarkdown: false }),
}

export default Markdown

export function sanitizer(str, { useUnsafeMarkdown = false } = {}) {
Expand Down
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/arrow-down.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const ArrowDown = ({ className, width, height, ...rest }) => (
const ArrowDown = ({ className = null, width = 20, height = 20, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
Expand All @@ -25,10 +25,4 @@ ArrowDown.propTypes = {
height: PropTypes.string,
}

ArrowDown.defaultProps = {
className: null,
width: 20,
height: 20,
}

export default ArrowDown
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/arrow-up.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const ArrowUp = ({ className, width, height, ...rest }) => (
const ArrowUp = ({ className = null, width = 20, height = 20, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
Expand All @@ -25,10 +25,4 @@ ArrowUp.propTypes = {
height: PropTypes.string,
}

ArrowUp.defaultProps = {
className: null,
width: 20,
height: 20,
}

export default ArrowUp
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/arrow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const Arrow = ({ className, width, height, ...rest }) => (
const Arrow = ({ className = null, width = 20, height = 20, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
Expand All @@ -25,10 +25,4 @@ Arrow.propTypes = {
height: PropTypes.string,
}

Arrow.defaultProps = {
className: null,
width: 20,
height: 20,
}

export default Arrow
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/close.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const Close = ({ className, width, height, ...rest }) => (
const Close = ({ className = null, width = 20, height = 20, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
Expand All @@ -25,10 +25,4 @@ Close.propTypes = {
height: PropTypes.string,
}

Close.defaultProps = {
className: null,
width: 20,
height: 20,
}

export default Close
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/copy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const Copy = ({ className, width, height, ...rest }) => (
const Copy = ({ className = null, width = 15, height = 16, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 15 16"
Expand All @@ -31,10 +31,4 @@ Copy.propTypes = {
height: PropTypes.string,
}

Copy.defaultProps = {
className: null,
width: 15,
height: 16,
}

export default Copy
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/lock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const Lock = ({ className, width, height, ...rest }) => (
const Lock = ({ className = null, width = 20, height = 20, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
Expand All @@ -25,10 +25,4 @@ Lock.propTypes = {
height: PropTypes.string,
}

Lock.defaultProps = {
className: null,
width: 20,
height: 20,
}

export default Lock
8 changes: 1 addition & 7 deletions src/core/plugins/icons/components/unlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from "react"
import PropTypes from "prop-types"

const Unlock = ({ className, width, height, ...rest }) => (
const Unlock = ({ className = null, width = 20, height = 20, ...rest }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
Expand All @@ -25,10 +25,4 @@ Unlock.propTypes = {
height: PropTypes.string,
}

Unlock.defaultProps = {
className: null,
width: 20,
height: 20,
}

export default Unlock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classNames from "classnames"

import { useComponent } from "../../hooks"

const Accordion = ({ expanded, children, onChange }) => {
const Accordion = ({ expanded = false, children, onChange }) => {
const ChevronRightIcon = useComponent("ChevronRightIcon")

const handleExpansion = useCallback(
Expand Down Expand Up @@ -42,8 +42,4 @@ Accordion.propTypes = {
onChange: PropTypes.func.isRequired,
}

Accordion.defaultProps = {
expanded: false,
}

export default Accordion
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "../../context"

const JSONSchema = forwardRef(
({ schema, name, dependentRequired, onExpand }, ref) => {
({ schema, name = "", dependentRequired = [], onExpand = () => {} }, ref) => {
const fn = useFn()
const isExpanded = useIsExpanded()
const isExpandedDeeply = useIsExpandedDeeply()
Expand Down Expand Up @@ -215,10 +215,4 @@ JSONSchema.propTypes = {
onExpand: PropTypes.func,
}

JSONSchema.defaultProps = {
name: "",
dependentRequired: [],
onExpand: () => {},
}

export default JSONSchema
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from "prop-types"
import { schema } from "../../../prop-types"
import { useFn } from "../../../hooks"

const Title = ({ title, schema }) => {
const Title = ({ title = "", schema }) => {
const fn = useFn()
const renderedTitle = title || fn.getTitle(schema)

Expand All @@ -25,8 +25,4 @@ Title.propTypes = {
schema: schema.isRequired,
}

Title.defaultProps = {
title: "",
}

export default Title
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from "prop-types"
import { schema } from "../../prop-types"
import { useFn } from "../../hooks"

const Type = ({ schema, isCircular }) => {
const Type = ({ schema, isCircular = false }) => {
const fn = useFn()
const type = fn.getType(schema)
const circularSuffix = isCircular ? " [circular]" : ""
Expand All @@ -24,8 +24,4 @@ Type.propTypes = {
isCircular: PropTypes.bool,
}

Type.defaultProps = {
isCircular: false,
}

export default Type
6 changes: 1 addition & 5 deletions src/core/plugins/oas3/wrap-components/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const parser = new Remarkable("commonmark")
parser.block.ruler.enable(["table"])
parser.set({ linkTarget: "_blank" })

export const Markdown = ({ source, className = "", getConfigs }) => {
export const Markdown = ({ source, className = "", getConfigs = () => ({ useUnsafeMarkdown: false }) }) => {
if(typeof source !== "string") {
return null
}
Expand Down Expand Up @@ -42,8 +42,4 @@ Markdown.propTypes = {
getConfigs: PropTypes.func,
}

Markdown.defaultProps = {
getConfigs: () => ({ useUnsafeMarkdown: false }),
}

export default OAS3ComponentWrapFactory(Markdown)
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ DiscriminatorMapping.propTypes = {
}),
}

DiscriminatorMapping.defaultProps = {
mapping: undefined,
}

export default DiscriminatorMapping

0 comments on commit d5a5146

Please sign in to comment.