Reactjs 如何将函数的返回值更改为int?

Reactjs 如何将函数的返回值更改为int?,reactjs,Reactjs,只需要做一个组件来更改页面,并返回页面的值(对于API)。第一个组件是用于更改页面的类,其余的是在MovePage的onClick函数中返回值的地方 export class MovePage extends React.Component { constructor(props) { super(props) this.decrementPage = this.decrementPage.bind(this) this.increment

只需要做一个组件来更改页面,并返回页面的值(对于API)。第一个组件是用于更改页面的类,其余的是在MovePage的onClick函数中返回值的地方

export class MovePage extends React.Component {
    constructor(props) {
        super(props)
        this.decrementPage = this.decrementPage.bind(this)
        this.incrementPage = this.incrementPage.bind(this)
    }

    render () {
        const incrementedPage = this.incrementPage
        return (
            <div className='changePage'>
                <button className='SelectionOff' id='decrement' onClick={()=>this.props.updatePage(this.decrementPage)}>Previous</button>
                <h1 className='changePageNumber'>{this.props.value}</h1>
                <button className='SelectionOff' id='increment' onClick={()=>this.props.updatePage(incrementedPage)}>Next</button>
            </div>
        )
    }
    decrementPage () {
        const newPage = this.props.value - 1
        return(newPage < 1 ? 1 : newPage )
      }
    incrementPage () {
        const newPage = this.props.value + 1
        return(typeof(newPage <= this.props.max ? newPage : this.props.value))
      }
}
在哪里返回参数

<MovePage value={this.state.page} max={this.state.max_pages} updatePage={this.updatePage}/>

 updatePage = (value) => {
    this.setState({page:value})
  }
警告:函数作为子函数无效。如果 返回一个组件,而不是从“渲染”返回。或许 您的意思是调用此函数而不是返回它


单击“下一步/上一步”按钮时。您传递函数this.decrementPage或this。将页面递增为updatePage函数

<button onClick={()=>this.props.updatePage(this.decrementPage)}>Previous</button>

this.props.value是一个函数。这就是你得到警告的原因。如果需要获取此.decrementPage函数的值。你需要把它叫做这个。递减页

将按钮中的onClick函数更改为类似onClick={=>this.props.updatePagetThis.decrementPage},而不是数字1、2、3、。。。打印号码你是什么意思?XD,我之前没有测试过,我用的是typeof,对不起,谢谢你提供的信息
<h1 className='changePageNumber'>{this.props.value}</h1>