export function navigate(name, params) { if (isMountedRef.current && navigationRef.current) { // Perform navigation if the app has mounted navigationRef.current.navigate(name, params); } else { // You can decide what to do if the app hasn't mounted // You can ignore this, or add these actions to a queue you can call later } }
changeBannerIndex(index) { this.setState({ currentIndex: index }); const banner = this.props.list[index]; const hasLink = banner.link != ''; this.setState({ hasLink }); if (hasLink) { this.elementLink.current.href = banner.link; } this.elementBanner.current.style.backgroundImage = `url(${banner.image})`; }
componentDidMount() { var mapStyle = JSON.parse(JSON.stringify(this.props.style)).style; map = new mapboxgl.Map({ container: this.mapboxElRef.current, style: mapStyle, center: [16, 27], zoom: 2, }); this.renderMap(map); }
updateAxis() { const axis = select(this.axisRef.current) .call(this.state.axis); if (this.props.orientation === AxisOrientation.BOTTOM && this.props.rotateText) { axis.selectAll('text') .style('text-anchor', 'end') .attr('dx', '-1em') .attr('dy', '-.2em') .attr('transform', 'rotate(-65)'); } }
handleSubmit(evt) { evt.preventDefault() ; fetch(`http://api.github.com/search/repositories?q=${this.inputName.current.value}`) .then(response => response.json()) .then(data => { this.setState({ list: data.items }) ; }) ; }
get _Canvas() { return this.canvasRef.current; }
function AutoFocus() { const textInput = createRef(); useEffect(() => { textInput.current.focus(); }); return ( <div> <input type="text" ref={textInput}></input> <button>click</button> </div> ); }
handleSearch() { const { onSearch } = this.props; const history = this.props.history; const textToSearch = encodeURI(this.refInput.current.value); if (textToSearch) { const url = `/search/${textToSearch}`; if (onSearch) onSearch(); history.push(url); } }