小编Aks*_*tel的帖子

如何在与Typecript的React中使用引用

我正在使用带有React的Typescript.我无法理解如何使用refs以获得关于refs引用的react节点的静态类型和intellisense.我的代码如下.

import * as React from 'react';

interface AppState {
    count: number;
}

interface AppProps {
    steps: number;
}

interface AppRefs {
    stepInput: HTMLInputElement;
}

export default class TestApp extends React.Component<AppProps, AppState> {

constructor(props: AppProps) {
    super(props);
    this.state = {
        count: 0
    };
}

incrementCounter() {
    this.setState({count: this.state.count + 1});
}

render() {
    return (
        <div>
            <h1>Hello World</h1>
            <input type="text" ref="stepInput" />
            <button onClick={() => this.incrementCounter()}>Increment</button>
            Count : {this.state.count}
        </div>
    );
}}
Run Code Online (Sandbox Code Playgroud)

typescript reactjs

88
推荐指数
7
解决办法
7万
查看次数

在React本机Webview中使用自定义字体

我在我的整个React本机应用程序中使用自定义字体.我使用react-native link命令链接了它们.除了Android的Webview组件之外,它们可以在任何地方工作.它在iOS Webview中正常运行.

import React, { Component } from "react"
import { View, StyleSheet, Text, WebView, ScrollView, Image } from "react-native"
import HTMLView from "react-native-htmlview"

export class PostDetailPage extends Component {

  static navigationOptions = {
    title: ({ state }) => state.params.post.title,
    header: {
      style: {
        backgroundColor: '#FF9800',
      },
      titleStyle: {
        color: 'white',
        fontFamily: "Ekatra",
        fontWeight: "normal"
      },
      tintColor: 'white'
    }
  }

  constructor(props) {
    super(props)
  }

  render() {
    const post = this.props.navigation.state.params.post
    const html = `
      <!DOCTYPE html>
      <html>
      <head>
        <style …
Run Code Online (Sandbox Code Playgroud)

css fonts android webview react-native

8
推荐指数
1
解决办法
6284
查看次数

标签 统计

android ×1

css ×1

fonts ×1

react-native ×1

reactjs ×1

typescript ×1

webview ×1