第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

反應(yīng)原生 - '未定義不是對(duì)象'?

反應(yīng)原生 - '未定義不是對(duì)象'?

慕神8447489 2022-11-11 16:32:32
好吧,離開(kāi)這個(gè)答案React native - “this.setState is not a function”試圖為背景顏色設(shè)置動(dòng)畫(huà)?我只是想在 React Native 中循環(huán)淡化視圖的背景顏色。export default props => {  let [fontsLoaded] = useFonts({    'Inter-SemiBoldItalic': 'https://rsms.me/inter/font-files/Inter-SemiBoldItalic.otf?v=3.12',        'SequelSans-RomanDisp' : require('./assets/fonts/SequelSans-RomanDisp.ttf'),        'SequelSans-BoldDisp' : require('./assets/fonts/SequelSans-BoldDisp.ttf'),        'SequelSans-BlackDisp' : require('./assets/fonts/SequelSans-BlackDisp.ttf'),  });  //Set states and hooks  //To change state 'color' - setColor('#ff0000');  const colors = ["#fff", "#ff0000", "#00ff00", "#0000ff", "#0077ff"];  const [color, setColor] = useState("#fff");  const [backgroundColor, setBackgroundColor] = useState(new Animated.Value(0));  const [time, setTime] = useState(0);  //const t = colors[randNum(0, colors.length)];  //random num, exclusive  function randNum(min, max) {    return Math.floor(min + Math.random() * (max - min));  }  useEffect(() => {    setBackgroundColor(new Animated.Value(0));  }, []); // this will be only called on initial mounting of component,  // so you can change this as your requirement maybe move this in a function which will be called,  // you can't directly call setState/useState in render otherwise it will go in a infinite loop.  useEffect(() => {    Animated.timing(backgroundColor, {      toValue: 100,      duration: 5000    }).start();  }, [backgroundColor]);  var bgColor = this.state.color.interpolate({    inputRange: [0, 300],    outputRange: ["rgba(255, 0, 0, 1)", "rgba(0, 255, 0, 1)"]  });  useEffect(() => {    const interval = setInterval(() => {      //setTime(new Date().getMilliseconds());      setColor("#ff0000");    }, 36000);    return () => clearInterval(interval);  }, []);有了這個(gè),一切都會(huì)檢查出來(lái),除了var bgColor = this.state.color會(huì)產(chǎn)生錯(cuò)誤undefined 不是評(píng)估的對(duì)象..我不明白為什么這是一個(gè)問(wèn)題,因?yàn)槲覍㈩伾O(shè)置為useState('#fff')我想color在我的樣式表中使用為backgroundColor.如何正確設(shè)置?
查看完整描述

3 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

如果你的組件是一個(gè)你不應(yīng)該使用的函數(shù)this.state.,但你必須直接調(diào)用狀態(tài)名稱(chēng)。

在您的代碼中:

var bgColor = color.interpolate({...})

代替:

var bgColor = this.state.color.interpolate({...})

從反應(yīng)文檔

閱讀狀態(tài)

當(dāng)我們想在一個(gè)類(lèi)中顯示當(dāng)前計(jì)數(shù)時(shí),我們讀取 this.state.count:

<p>You clicked {this.state.count} times</p>

在函數(shù)中,我們可以直接使用count:

<p>You clicked {count} times</p>


查看完整回答
反對(duì) 回復(fù) 2022-11-11
?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

這是一個(gè)示例,不要為動(dòng)畫(huà)值創(chuàng)建狀態(tài),而是使用備忘錄對(duì)其進(jìn)行一次初始化并使用計(jì)時(shí)功能對(duì)其進(jìn)行更新


小吃:https ://snack.expo.io/GwJtJUJA0


代碼:


export default function App() {

  const { value } = React.useMemo(

    () => ({

      value: new Animated.Value(0),

    }),

    []

  );


  React.useEffect(() => {

    Animated.loop(

      Animated.sequence([

        Animated.timing(value, {

          toValue: 1,

          duration: 1000,

        }),

        Animated.timing(value, {

          toValue: 0,

          duration: 1000,

        })

      ])

    ).start();

  }, []);


  const backgroundColor = value.interpolate({

    inputRange: [0, 1],

    outputRange: ['#0dff4d', '#ff390d'],

  });


  return (

    <View style={styles.container}>

      <Animated.View style={{ width: 200, height: 100, backgroundColor }} />

    </View>

  );

}


查看完整回答
反對(duì) 回復(fù) 2022-11-11
?
侃侃無(wú)極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

在功能組件中,您不使用 訪問(wèn)組件的狀態(tài)屬性/變量this.state.abc,而是直接使用狀態(tài)變量的名稱(chēng)。所以你應(yīng)該做的是:


    var bgColor = color.interpolate({

      inputRange: [0, 300],

      outputRange: ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)']

    });


查看完整回答
反對(duì) 回復(fù) 2022-11-11
  • 3 回答
  • 0 關(guān)注
  • 171 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)